Kennywen
asked on
Set focus on JComboBox
How can i set focus on JComboBox??? i checked the JComboBox API but didn't get the setFocus property.
thanks
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try an updateUI () call for your container (which contains the JComboBox) after requestFocus ().
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
dBox.requestFocus();
until it is really needed and after all (window/frame/dialog) initialization is done.
Maybe you can post more complete code
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
http://javaalmanac.com/egs/java.awt/focus_InitialFocus.html
Can it not be done in a statement just after show () or setVisible ( true ) ?
I mean - the updateUI () ?
Try it:
combo.requestFocusInWindow ();
I hope that it helps,
ROB
combo.requestFocusInWindow
I hope that it helps,
ROB
ASKER
i solve the problem by using coding below:
myFrame.setResizable(false );
dBox.requestFocus();
myFrame.setVisible(true);
any disadvantage on above code?
thanks
myFrame.setResizable(false
dBox.requestFocus();
myFrame.setVisible(true);
any disadvantage on above code?
thanks
If what i first suggested is working, then stick with that
ASKER
sure i will but just want to know any disadvantage on it?
Not having a deep enough knowledge of focus - i'd probably resort to trial and error myself ;-)
8-)
ASKER
dBox.addActionListener(thi
dBox.setActionCommand("Com
dBox.requestFocus();
but the combobox doesn't get focus.
thanks