• Post Reply Bookmark Topic Watch Topic
  • New Topic

JComboBox With Disabled Items

 
Joel de Matos
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • 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
 
Jason Steele
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • 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
  • 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!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!