Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Focus Between JComboBox and JTextField

 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is this in a JTabbedPane?

if so, use a timer for the requestFocusInWindow(), 250ms should do
 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic