• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2629
  • Last Modified:

Set focus on JComboBox

How can i set focus on JComboBox??? i checked the JComboBox API but didn't get the setFocus property.

thanks
0
Kennywen
Asked:
Kennywen
  • 5
  • 3
  • 3
  • +2
1 Solution
 
CEHJCommented:
combo.requestFocus();
0
 
KennywenAuthor Commented:
JComboBox dBox = new JComboBox(dLists);
dBox.addActionListener(this);
dBox.setActionCommand("Combo1");
dBox.requestFocus();

but the combobox doesn't get focus.

thanks
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Try an updateUI () call for your container (which contains the JComboBox) after requestFocus ().
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
zzynxSoftware engineerCommented:
You better wait to perform

         dBox.requestFocus();

until it is really needed and after all (window/frame/dialog) initialization is done.

Maybe you can post more complete code
0
 
CEHJCommented:
You really need to do this in a window listener if you want this to happen as soon as your app is shown. See

http://javaalmanac.com/egs/java.awt/focus_InitialFocus.html
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Can it not be done in a statement just after show () or setVisible ( true ) ?
0
 
Mayank SAssociate Director - Product EngineeringCommented:
I mean - the updateUI () ?
0
 
RobCSPCommented:
Try it:


combo.requestFocusInWindow();


I hope that it  helps,

ROB
0
 
KennywenAuthor Commented:
i solve the problem by using coding below:

myFrame.setResizable(false);
dBox.requestFocus();
myFrame.setVisible(true);

any disadvantage on above code?

thanks
0
 
CEHJCommented:
If what i first suggested is working, then stick with that
0
 
KennywenAuthor Commented:
sure i will but just want to know any disadvantage on it?
0
 
CEHJCommented:
Not having a deep enough knowledge of focus - i'd probably resort to trial and error myself ;-)
0
 
CEHJCommented:
8-)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 5
  • 3
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now