Solved

JTree - how to change the Icon on each single leaf

Posted on 2007-03-25
5
575 Views
Last Modified: 2013-12-29
Hi,
in my JTree I would like to change the leaf icon depending on the status that the entry currenty has.
Example:
....
ImageIcon leafIcon_nio = createImageIcon("images/nio.png");
renderer_nio = new TreeCellRenderer();
renderer_nio = new DefaultTreeCellRenderer();

for(int werke=0;werke<anz_werke.size();werke++){
      int i=0;
      category = new DefaultMutableTreeNode(anz_werke.elementAt(werke));
      top.add(category);
      while(i<V_KUNDENWERK.size()){
            if(V_KUNDENWERK.elementAt(i).equals(anz_werke.elementAt(werke))){
--------------->
                                if(V_erledigt.elementAt(i).toString().equalsIgnoreCase("Ja")){
                                        renderer_io.setLeafIcon(leafIcon_io);
                                }
                              else
                              {
                                        renderer_io.setLeafIcon(leafIcon_io);
                              }
--------------->
                  book = new DefaultMutableTreeNode("QST:"+(String)V_QEC_QST_NR.elementAt(i));
                  category.add(book);
            }
            i++;
      }
}

I know, it's wrong (it doesn't work) but I don't know how to change.
I got only all Icons changed but thats not the target.

Who can help me?

0
Comment
Question by:arempka
  • 2
  • 2
5 Comments
 
LVL 30

Accepted Solution

by:
Mayank S earned 250 total points
ID: 18789654
You can implement TreeCellRenderer or extend DefaultTreeCellRenderer. Use the source code provided:

http://forum.java.sun.com/thread.jspa?threadID=262758&messageID=1712649
0
 
LVL 92

Expert Comment

by:objects
ID: 18790276
0
 

Author Comment

by:arempka
ID: 18806175
Hello mayankeagle,

SimpleCellRenderer is exactly what I was serching for.
Only Problem:
In the main application I implemented a ImageIcon with the path "images/io.png".
This image was found and shown when starting from the .jar File.
Now, with the same Path in the SimpleCellRenderer it is working in the eclipse environment and command line start but the Images were not when starting from .jar- File.

What's wrong?

Regards

Arempka
0
 

Author Comment

by:arempka
ID: 18807772
Hello mayankeagle,

SimpleCellRenderer is exactly what I was serching for.
Only Problem:
In the main application I implemented a ImageIcon with the path "images/io.png".
This image was found and shown when starting from the .jar File.
Now, with the same Path in the SimpleCellRenderer it is working in the eclipse environment and command line start but the Images were not when starting from .jar- File.

What's wrong?

Regards

Arempka
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18807910
Try loading it as a resource using getClass ().getResource ()
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
servlet doXXX methods 3 62
print map entry 34 72
Arrays.asList  VS  ArrayList 4 71
Glassfish admin console not working 1 33
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question