Solved

Set focus on JComboBox

Posted on 2004-04-02
13
2,307 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 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

696 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