Solved

Set focus on JComboBox

Posted on 2004-04-02
13
2,205 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
firstswap challenge 20 65
What is the latest versions eclipse neon 2 139
Basic Java Case or If-Else statement... 3 43
Apps blocked by Java 9 55
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

930 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now