File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "Focus Between JComboBox and JTextField" Watch "Focus Between JComboBox and JTextField" New topic
Author

Focus Between JComboBox and JTextField

Ankur Sharma
Ranch Hand

Joined: Dec 27, 2005
Posts: 1234
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
Ankur Sharma
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
Ankur Sharma
Ranch Hand

Joined: Dec 27, 2005
Posts: 1234
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.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Focus Between JComboBox and JTextField
 
Similar Threads
Swing JOptionPane showInputDialog : own textfield or combobox
Do MouseEvents work on JComboBox
JTree CellEditor with Combobox and Textfield
Regarding JTextfield and Jlabel
how to search in a JComboBox