Results 1 to 7 of 7
- 10-22-2012, 02:58 PM #1
Member
- Join Date
- Oct 2012
- Posts
- 3
- Rep Power
- 0
Dynamically changing icons of some nodes in a JTree
Hi,
I am looking to change the icons in a Jtree nodes depending on some condition. For Example I am populating n number of Jobs in the Jtree under a single parent by reading a folder for xml files.
and some of the jobs might be currently running and i wish to show the icons for these running jobs with a green dot to differentiate them from other jobs. As follows
Jobs
#job1
#job2
#job3
[OR]
Jobs
#job1
#job2
#job3
I just need to differentiate it from other jobs be it the icon changing or the text color changing.
Any suggestions?
Regards
--vishnu--
- 10-22-2012, 03:14 PM #2
Re: Dynamically changing icons of some nodes in a JTree
Sounds like a job for a renderer. Recommended reading: How to Use Trees (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 10-22-2012, 03:23 PM #3
Member
- Join Date
- Oct 2012
- Posts
- 3
- Rep Power
- 0
Re: Dynamically changing icons of some nodes in a JTree
Thank you Kevin! But i have already been through this link and cant find any help. i tried the following scenario just to change the images and it did not work.
I tried whit a sleep of 1000 and i can only see the blue icon always. The green doesnt seem to show up atall even after i adjust the sleep timing. If i remove the call for the changeNodeIcons11(), then i can see the green icons.
private void jButton_changeActionPerformed(java.awt.event.Actio nEvent evt) {
// TODO add your handling code here:
changeNodeIcons();
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
Logger.getLogger(EasyLoaderPro.class.getName()).lo g(Level.SEVERE, null, ex);
}
changeNodeIcons1();
}
public void changeNodeIcons() {
ImageIcon greenIcon = new ImageIcon(".\\src\\treetest\\images\\greendot.gif" );
DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) job_tree.getCellRenderer();
if (greenIcon != null) {
System.out.println("Green icon Found");
renderer.setLeafIcon((Icon) greenIcon);
job_tree.setCellRenderer(renderer);
job_tree.invalidate();
job_tree.repaint();
} else {
System.err.println("Leaf icon missing; using default.");
}
}
public void changeNodeIcons1() {
ImageIcon blueIcon = new ImageIcon(".\\src\\treetest\\images\\bluedot.gif") ;
DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) job_tree.getCellRenderer();
if (blueIcon != null) {
renderer = (DefaultTreeCellRenderer) job_tree.getCellRenderer();
renderer.setLeafIcon((Icon) blueIcon);
job_tree.setCellRenderer(renderer);
job_tree.invalidate();
job_tree.repaint();
} else {
System.err.println("Leaf icon missing; using default.");
}
}
- 10-22-2012, 03:42 PM #4
Re: Dynamically changing icons of some nodes in a JTree
Don't call Thread.sleep() on the EDT. You won't be able to see anything happening while the EDT is sleeping, since you're blocking the painting thread.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 10-22-2012, 03:46 PM #5
Re: Dynamically changing icons of some nodes in a JTree
Nevermind, crossposted: Dynamically changing icons of some nodes in a JTree
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 10-22-2012, 03:52 PM #6
Member
- Join Date
- Oct 2012
- Posts
- 3
- Rep Power
- 0
Re: Dynamically changing icons of some nodes in a JTree
Kevin,
I appreciate your help very much.
Its' just that I did not know that these two forums are the same. I thought they were different. If not i would never have cross posted this. I was just looking for a quick solution and hence thought i might get different people on different forums .
- 10-23-2012, 02:33 PM #7
Re: Dynamically changing icons of some nodes in a JTree
Please go through Guide For New Members and BB Code List - Java Programming Forum
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
help with jtree icons
By ankit_k in forum AWT / SwingReplies: 4Last Post: 06-16-2011, 08:18 PM -
Adding Icons to JTree
By Nidi in forum New To JavaReplies: 3Last Post: 02-19-2011, 12:23 PM -
Netbeans: Add nodes to JTree?
By mishathegoat in forum AWT / SwingReplies: 8Last Post: 11-15-2010, 01:55 AM -
How to dynamically add Nodes to JTree?
By javanewbie in forum AWT / SwingReplies: 3Last Post: 07-13-2009, 07:20 AM -
Nodes displayed in JTree
By Orange in forum AWT / SwingReplies: 6Last Post: 08-08-2008, 05:07 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks