File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Android Security Essentials Live Lessons this week in the Android 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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Prevent user from changing display item in JComboBox ?
 
Similar Threads
gridlayout with combo box
Different Cursors
Swing - detect mouse click outside modal JDialog boundary
setEditable(true) function of jcombobox not working
JComboBox ItemListener passing typed key to JTextField