File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JList selection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JList selection" Watch "JList selection" New topic
Author

JList selection

Eric Chang
Ranch Hand

Joined: Jan 27, 2004
Posts: 113
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?
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 863
    
    1
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.


bitguru blog
Eric Chang
Ranch Hand

Joined: Jan 27, 2004
Posts: 113
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JList selection