This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTree, empty folders (nodes) icon  RSS feed

 
Mathew Mintalm
Ranch Hand
Posts: 103
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, Im making my own JTree (with new TreeModel)

Till now everything works fine:



As you can see, i just selected "Empty folder" and in fact this is empty folder (im loading files from my system into JTree)

And you can see, there is difference, empty folder looks like normal file (icon)

So my question is, how can i set the same icon as there is for folder with content?

I would also like to notice that this "folder with content icon" is set by Nimbus Look and feel (its not my icon)

Thanks in advice!
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the description of the isLeaf() method in the TreeModel interface (which your post actually links to). It actually chooses your example as its example.
 
Mathew Mintalm
Ranch Hand
Posts: 103
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hm, I can't really find any example there relleated with my problem.

Can you give me a bit more info please?
 
Rob Spoor
Sheriff
Posts: 21048
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you haven't read the Javadoc. It clearly states
Returns true if node is a leaf. It is possible for this method to return false even if node has no children. A directory in a filesystem, for example, may contain no files; the node representing the directory is not a leaf, but it also has no children.
 
Mathew Mintalm
Ranch Hand
Posts: 103
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did, ofc i did.

But i don't have any idea now how to use it to solve this problem.
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I recall from when I did this several years ago, you have to override the isLeaf and hasChildren methods in your TreeModel to return the right information for empty and non-empty folders. I don't remember exactly what that information was, but there's only four possibilities so a little experimentation should turn up the right answer.
 
Mathew Mintalm
Ranch Hand
Posts: 103
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok guys, thanks anyway.

I found my solution, with new CellRenderer extends DefaultTreeCellRenderer class, and as I can see, works fine.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!