• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

JList

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.)
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic