Solved

JTree - how to change the Icon on each single leaf

Posted on 2007-03-25
5
581 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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
login jsp example 24 105
ejb example issues 3 90
java imports not found 4 71
Java import explained 4 49
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

752 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