Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Prevent user from changing display item in JComboBox ?

 
achana chan
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 :-)
 
Serghei Jelauc
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Put this string petList.setSelectedIndex(4); in your ActionListener
 
achana chan
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the Swing forum.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic