How do I get the focus in the file name text field of JFileChooser when I open a save dialog?

Sandip Chitale

JFileChooser is a Component and not a Dialog. The showDialog(...) methods are convinience APIs to wrap it in a modal Dialog and show it.

One could do the same thing manually. For example you could override the showDialog method. In it you could create a Dialog and JFileChooser ('this') to it. Add a ComponentListener and a WidnowListener to the dialog. Then show the Dialog.

In the componentShown(...) or windowOpenend(...) or a windowActivated(...) callbacks of the listeners drill down looking for a JTextField. Once found call requestFocus() on the JTextField.

You will have to be carefull about finding the right JTextField based on the current look and feel.
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact