This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Custom Icons in JTree

 
Jeremy Hooie
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to place custom icons in a JTree to replace the standard folders and pages?
Thanks,
Jeremy
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know how to change the Leaf Icon.
myDefaultTreeCellRenderer.setLeafIcon(new ImageIcon("somefile.gif"));
Probably similar for the nodes and root.

------------------
Happy Coding,
Gregg Bolinger
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, to set the Open Folder Icon you do the same except, setOpenIcon(new ImageIcon());
and the setClosedIcon(new ImageIcon()) sets the closed folder Icon.

------------------
Happy Coding,
Gregg Bolinger
 
Jeremy Hooie
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm setting everything as a DefaultMutableTreeNode. I execute a SQL statement and step through the ResultSet to add each element as a node. Then I create a tree model passing that node to the constructor. Is there a way to change the icon of a node so that I don't have to recode the tree using leafs?
Jeremy
 
Matt Hansen
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can implement a TreeRenderer and use the getTreeCellRendererComponent to specify the icon of each node.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic