aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Focus Between JComboBox and JTextField Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Focus Between JComboBox and JTextField" Watch "Focus Between JComboBox and JTextField" New topic
Author

Focus Between JComboBox and JTextField

Shaan Shar
Ranch Hand

Joined: Dec 27, 2005
Posts: 1249

Hi All,

I have a screen in which I have used flow layout, and in this screen there are two components 1. JComboBox and 2. JtextField.

Now the problem is JCombobox is first component and after that jTextField is displayed, Now I have used below method to setFocus as the screen starts. But it is not working...



But still Combobox is getting focused as we start the screen. What I have analyzed is that it might be because, JCombobox is itself is Component.
Can any body help me, how can I getFocus on TextField.


The Best way to predict your future is to create it - Every great individual common man
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
is this in a JTabbedPane?

if so, use a timer for the requestFocusInWindow(), 250ms should do
Shaan Shar
Ranch Hand

Joined: Dec 27, 2005
Posts: 1249

Originally posted by Michael Dunn:
is this in a JTabbedPane?

if so, use a timer for the requestFocusInWindow(), 250ms should do


No it's not JTabbedPane....... and even it's not working If I am using requestFocusInWindow().
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
requestFocusInWindow() must be called after the frame is visible, so
invokeLater should work.

try setting frame.setVisible(true) before the SwingUtilities, if still not working
post a short demo program, so we can see how you have put it together.
 
Consider Paul's rocket mass heater.
 
subject: Focus Between JComboBox and JTextField