• 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

JList selection

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I have to implement what is a highly customized File Chooser (I wish I could use the JFileChooser, but this is a bit more complex...plus JFileChooser is evil).

So in my customized chooser, I have a list of all the files and sub directories within a JList. I want the files to just be listed and grayed out and not able to be selected. I want the directories to be selectable and not grayed out. If a user double clicks on the subdirectory, it will navigate to the subdirectory and display it's contents, etc. If a user just selects the subdirectory (and not double-click), it will select that entry in the JList and fill in the JTextField elsewhere in the chooser dialog.
The part I'm stuck on is getting the JList to display selectable and unselectable items (not to mention the grayed out color of the unselectable items)...is this a case where I want to start messing around with the CellRenderer?
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Eric Chang:
I have a list of all the files and sub directories within a JList. I want the files to just be listed and grayed out and not able to be selected. I want the directories to be selectable and not grayed out.

The part I'm stuck on is getting the JList to display selectable and unselectable items (not to mention the grayed out color of the unselectable items)...is this a case where I want to start messing around with the CellRenderer?



Yes. You want to set a cell renderer for the JList to display some items
in a greyed-out color. This is actually pretty simple. For example, to
grey-out every other item in the list:

This changes just how those items are drawn. It doesn't change whether
they can be selected or not. For that take a look at ListSelectionModel.
 
Eric Chang
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I got that part working...I'm attempting to figure out the selection part now. Thanks for your help and hopefully I can get the rest by myself.
 
reply
    Bookmark Topic Watch Topic
  • New Topic