IntelliJ Java IDE
The moose likes Swing / AWT / SWT / JFace and the fly likes How to add icons along with the text in a JList[urgent] Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT / JFace
Reply Bookmark "How to add icons along with the text in a JList[urgent]" Watch "How to add icons along with the text in a JList[urgent]" New topic
Author

How to add icons along with the text in a JList[urgent]

netharam ram
Ranch Hand

Joined: Aug 09, 2001
Posts: 202
Hi, I have Jlist that lists the files & folders in as pecified path.I want to differentiate folders from files,so I wish to add a folder icon along with the folder path in the Jlist.Is this Possible?Please reply me as soon as possible.
Happy middling with java.
Netharam :roll:
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4120

All you have to do is extend DefaultListCell Renderer to do what you want (if the current item is a directory, add an icon showing it is a Directory instead of a file), then call setCellRenderer() on your JList with an instance of your new ListCellRenderer.

-Nate


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
netharam ram
Ranch Hand

Joined: Aug 09, 2001
Posts: 202
HI, Nathan could u please reply with a code snippet for I've very less knowledge in swing.
Happy middling with java. :
Netharam. :roll:
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4120

Here's some code that should help you out with your renderer problem...



-Nate
 
 
subject: How to add icons along with the text in a JList[urgent]
 
Threads others viewed
Show the selected file and folder in tree structure with checkbox and the checkbox should be only..
regarding jFileChooser
Dynamic checkbox JTree
To add icon top of the text in JList
To add Icons along with text in a JList[urgent.........]
developer file tools