Article View: borland.public.jbuilder.java.swing
Article #10975Icons for each node in a Tree
From: Firoz T M
Date: Fri, 23 Jul 1999 00:00
Date: Fri, 23 Jul 1999 00:00
121 lines
3237 bytes
3237 bytes
Hi,
am porting an existing C++ app to Java. This application contains a
TREE CONTROL. Each main node is having a different ICONS....
How can I achieve this???? If any one know, please let me know...
Inorder to achieve this, I wrote a class which uses JTree in it..
This class uses My own derived Renderer.... But when using this, itz not
displaying any icons....
Any help is appreciated.....
The Render class is as follows...
----------------------------------
class WFCTreeRenderer extends DefaultTreeCellRenderer {
public WFCTreeRenderer() {
}
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);
Icon icon = ((IconNode)value).getIcon();
if (icon == null)
{
String name = ((IconNode)value).getIconName();
if (name != null)
{
icon = (Icon)icons.get(name);
if (icon != null)
{
setIcon(icon);
}
}
}
else
{
setIcon(icon);
}
return this;
}
}
IconNode.java
-------------
import java.util.*;
import javax.swing.*;
import javax.swing.tree.*;
public class IconNode extends DefaultMutableTreeNode {
protected Icon icon;
protected String iconName;
public IconNode() {
this(null);
}
public IconNode(Object userObject) {
this(userObject, true, null);
}
public IconNode(Object userObject, boolean allowsChildren
, Icon icon) {
super(userObject, allowsChildren);
this.icon = icon;
}
public void setIcon(Icon icon) {
this.icon = icon;
}
public Icon getIcon() {
return icon;
}
public String getIconName()
{
return iconName;
}
public void setIconName(String name) {
iconName = name;
}
}
--
----------------------------------------------------------------
FIROZ T M firoz@procsys.com
----------------------------------------------------------------
Quote for the day
Please Tell Me if you Don't Get This Message
----------------------------------------------------------------
This is through WebEtc Mail Server.....
Technical Details
Message-ID:
<379871C9.588B936C@procsys.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,240329fa40c08b00,start X-Google-Attributes: gid111d45,public From: Firoz T M <firoz@procsys.com> Subject: Icons for each node in a Tree Date: 1999/07/23 Message-ID: <379871C9.588B936C@procsys.com> X-Deja-AN: 504401150 Content-Transfer-Encoding: 7bit Organization: Another Netscape Collabra Server User X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing