• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JComboBox With Disabled Items

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello guys, i really need your help with a problem here...
I have a normal JComboBox with 3 items, but what i want is all the items to be disabled. If not possible, than only the default value may be enabled, but the other choices must be disabled (grayed out and not chooseable).
I need this because the user of my app must see all the possible values for a question, but he will be forced to use the default (and correct) one.
can you help? it is very important
thanks
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Joel,
I think the best answer for you would be to use a custom ListCellRenderer.
Something like:

then define CustomListCellRenderer as:


Happy Coding!
I believe this should disable all cells!
 
Jason Steele
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Joel,
I apologize, after coding it myself, the if-statement should look as follows:


this works because I tried it!
Note: set the first list item to be the correct answer!
 
reply
    Bookmark Topic Watch Topic
  • New Topic