Setting focus on a JTextField when a JOptionPane is displayed.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Stephen_Smith
Posted On:   Thursday, June 19, 2003 08:37 AM

Hi,

			
JTextField textOne = new JTextField();
JTextField textTwo = new JTextField();
JPanel panel = new JPanel();
panel.add(textOne);
panel.add(textTwo);
JOptionPane.showMessageDialog(null, panel, "demo", JOptionPane.OK_CANCEL_OPTION);


In the above code, how can I make the JOptionPane appear with one of the text fields having the focus?

Thanks,

Steve.

Re: Setting focus on a JTextField when a JOptionPane is displayed.

Posted By:   Sandip_Chitale  
Posted On:   Wednesday, June 25, 2003 08:10 AM

Instead of using the static showXXXDialog method use a suitable JDialog CTOR. Then add a windowListener to it and in the windowOpened or windowActivated callback set the focus in the text field. Then show the JDialog instance.
About | Sitemap | Contact