• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
netharam ram
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
netharam ram
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's some code that should help you out with your renderer problem...



-Nate
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic