Solved

Set focus on JComboBox

Posted on 2004-04-02
13
2,267 Views
Last Modified: 2012-06-21
How can i set focus on JComboBox??? i checked the JComboBox API but didn't get the setFocus property.

thanks
0
Comment
Question by:Kennywen
  • 5
  • 3
  • 3
  • +2
13 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 25 total points
ID: 10739254
combo.requestFocus();
0
 

Author Comment

by:Kennywen
ID: 10739268
JComboBox dBox = new JComboBox(dLists);
dBox.addActionListener(this);
dBox.setActionCommand("Combo1");
dBox.requestFocus();

but the combobox doesn't get focus.

thanks
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10739293
Try an updateUI () call for your container (which contains the JComboBox) after requestFocus ().
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 37

Expert Comment

by:zzynx
ID: 10739300
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 10739341
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
 
LVL 30

Expert Comment

by:Mayank S
ID: 10739369
Can it not be done in a statement just after show () or setVisible ( true ) ?
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10739376
I mean - the updateUI () ?
0
 

Expert Comment

by:RobCSP
ID: 10739380
Try it:


combo.requestFocusInWindow();


I hope that it  helps,

ROB
0
 

Author Comment

by:Kennywen
ID: 10739397
i solve the problem by using coding below:

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

any disadvantage on above code?

thanks
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10739413
If what i first suggested is working, then stick with that
0
 

Author Comment

by:Kennywen
ID: 10739422
sure i will but just want to know any disadvantage on it?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10739434
Not having a deep enough knowledge of focus - i'd probably resort to trial and error myself ;-)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10739456
8-)
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
simple java question 3 59
How do I remove an object from a 3 40
ejb on wildfly 5 30
ejb entity bean example issue 2 16
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question