How to focus on a textfield when a dialog is opened?

I have a "ConnectServerDialog" which contains a "textfield", I want the textfield to be focused when the dialog is shown.

 
class ConnectServerDialog extends DialogWrapper {
 
}
  
I tried to invoke:
  
    textfield.requestFocus()
  
or 
  
    textfield.requetFoucsInWinows()
  
But neither works. 
  
What's the correct solution?
2 comments
Comment actions Permalink

Override com.intellij.openapi.ui.DialogWrapper#getPreferredFocusedComponent and return the component to be initially focused there.


1
Comment actions Permalink

That works! Thank you so much

0

Please sign in to leave a comment.