• Post Reply Bookmark Topic Watch Topic
  • New Topic

JList  RSS feed

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks,
my JList should show several entries where one is selected. On the other hand the JList should be disabled so that the user cannot select a different entry. In this use case the JList is only used to show information and not to handle user events.
How can I do this? I don't want to use "JList.setEnabled(false)",
because then the entries are gray-colored and hard to see, especially the selected one!
Thanks in advance!
 
Jesper Ottosson
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
save the state of the list in some Map or List somewhere, then add a MouseListener to the JList, and when you detect a mouseclick, use JList.setSelection() (I think that's what it's name is) to set it back to normal again.
Ehrr... perhaps this isnt the most beautiful solution, take another look through the api-docs before you do it
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try the setSelectionMode(int selectionMode) method. I think this is what you are looking for. Check the api doc for the JList selectionMode constants.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help guys, but meanwhile I found a solution by my own. I use an own CellRenderer defining my JList-Cells that I assign to my JList by
myList.setCellRenderer( new MyCellRenderer);
If someone has a similar problem he should look into the API pages of SWING (CellRenderer, etc.)
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!