wood burning stoves*
The moose likes Swing / AWT / SWT and the fly likes Prevent user from changing display item in JComboBox ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Prevent user from changing display item in JComboBox ?" Watch "Prevent user from changing display item in JComboBox ?" New topic
Author

Prevent user from changing display item in JComboBox ?

achana chan
Ranch Hand

Joined: Jul 29, 2002
Posts: 277
Hi.
If some conditions are fulfilled, I would like to prevent the user from selecting other items in the JCombobox list i.e. if the user clicks on another item other than the default one in setSelectedIndex, the display will not change and stay the same e.g.

In this code the entry "pig" is displayed as the default, but if the user clicks on "cat", that the display is set to "cat".
I want to prevent that, so that "pig" is always displayed regardless what other pets the user might click on.
TIA :-)


humanum errare est.
Serghei Jelauc
Ranch Hand

Joined: Jul 24, 2002
Posts: 128
Put this string petList.setSelectedIndex(4); in your ActionListener


SCJP 1.4 <br />SCBCD 1.3<br />SCWCD 1.4
achana chan
Ranch Hand

Joined: Jul 29, 2002
Posts: 277
Thanks for your help.
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Moving to the Swing forum.


"JavaRanch, where the deer and the Certified play" - David O'Meara
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Prevent user from changing display item in JComboBox ?
 
Similar Threads
Swing - detect mouse click outside modal JDialog boundary
Different Cursors
JComboBox ItemListener passing typed key to JTextField
gridlayout with combo box
setEditable(true) function of jcombobox not working