Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Empty directories are shown as leaf nodes while using JTree to display filesystem  RSS feed

 
Chandra Sekar
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm using JTree to display the contents of the selected directory recursively. Now when an empty directory is present on the filesystem, it is displayed as a leaf node as it does not have any child.

How do I use the parent node icon for empty directories?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using any special TreeCellRenderers with your tree? You could display the desired icon using a file.isDirectory() test inside the renderer.
 
Chandra Sekar
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not using special tree cell renderer. Using isDirectory is fine, but how do I specify the icon to use?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm... that's why I was asking if you were using any TreeCellRenderers - you'd have to specify that in your own TreeCellRenderer -

Something like -

 
Chandra Sekar
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, that clears it for me.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!