Results 1 to 4 of 4
Thread: Adding Icons to JTree
- 02-19-2011, 11:01 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 4
- Rep Power
- 0
Adding Icons to JTree
Hello...
Can any one help me out to slove this problem...
I am creating Jtree in a UI. I need to add same icons to one parent node and for different parent node, different icons. I used below code...
DefaultTreeCellRenderer renderer3 = new DefaultTreeCellRenderer();
renderer3.setLeafIcon(customLeafIcon);
tree3.setCellRenderer(renderer3);
After using this same icon is displaying for all parent node...:confused:
can any one tell me what is the mistake....
Thanks in advance
nidi
:)
- 02-19-2011, 11:30 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,392
- Blog Entries
- 7
- Rep Power
- 17
Extend the DefaultTreeCellRenderer class and override the following method:
The second parameter is the current tree node object; according to its type you set a different icon using the setIcon( ... ) method (a renderer extends a JLabel so you can set their icon).Java Code:public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { ... }
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-19-2011, 11:51 AM #3
Member
- Join Date
- Feb 2011
- Posts
- 4
- Rep Power
- 0
Thank you Jos.... I will definitely try this method.... :)
- 02-19-2011, 12:23 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,392
- Blog Entries
- 7
- Rep Power
- 17
Good; a skeleton of the method you need to implement in your class looks like this:
kind regards,Java Code:public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); // setIcon( ... ) according the the type of value return this; }
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
New Posts Icons
By desertlizard in forum Suggestions & FeedbackReplies: 3Last Post: 12-06-2010, 05:00 PM -
Move JTree item to another JTree.
By Melki in forum AWT / SwingReplies: 8Last Post: 07-09-2009, 11:59 AM -
[SOLVED] Adding JTree, JTable inside a JTabbedPane
By javanewbie in forum AWT / SwingReplies: 6Last Post: 05-28-2009, 05:32 AM -
how to compare icons
By panic in forum New To JavaReplies: 9Last Post: 05-21-2009, 08:16 AM -
is there anyone how can help me with image icons please?
By xbox_nutter in forum New To JavaReplies: 4Last Post: 03-27-2009, 10:26 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks