?
Solved

Set focus on JComboBox

Posted on 2004-04-02
13
Medium Priority
?
2,426 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 3
  • +2
13 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 100 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month14 days, 4 hours left to enroll

801 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