Article View: borland.public.jbuilder.java.language
Article #16975Re: JTree node icon
From: Nick Ring
Date: Thu, 07 Jan 1999 00:00
Date: Thu, 07 Jan 1999 00:00
51 lines
1986 bytes
1986 bytes
On Wed, 6 Jan 1999 10:33:25 -0000, "Jonathan" <plaskowj@logica.com>
wrote:
>I want to change the icon representing the node at the bottom levels of my
>JTree, how do i implement this?
What I did was to extend JLabel while implementing TreeCellRenderer.
When you override getTreeCellRendererComponent (which you have to when
you implement TreeCellRenderer) you workout what text/icon you want to
have at that node (be it a leaf or a branch) and return this (the
JLabel) for example (which is a part of the code I used)...
public Component getTreeCellRendererComponent(JTree tree, Object
value, boolean selected, boolean expanded, boolean leaf, int row,
boolean hasFocus)
{
if (dmtn.isRoot())
{
this.setIcon((Icon) UIManager.get("FileView.computerIcon"));
}
else
{
if (dmtn.getParent().equals(dmtn.getRoot()))
{
this.setIcon((Icon) UIManager.get("FileView.hardDriveIcon"));
}
else
{
if (selected)
{
this.setIcon((Icon) UIManager.get("Tree.openIcon"));
}
else
{
this.setIcon((Icon) UIManager.get("Tree.closedIcon"));
}
}
}
// do what ever you need to do before returning.
return this;
}
>many thanks
Hope it helps,
nick
--
remove "NOSPAM." to get my real email address
Technical Details
Message-ID:
<36950edd.328610@news.southcom.com.au>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<76ve2f$cdn16@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,9eb1117c9911f589 X-Google-Attributes: gidf74b3,public From: nring@NOSPAM.southcom.com.au (Nick Ring) Subject: Re: JTree node icon Date: 1999/01/07 Message-ID: <36950edd.328610@news.southcom.com.au> X-Deja-AN: 429908682 References: <76ve2f$cdn16@forums.borland.com> X-Complaints-To: abuse@connect.com.au X-Trace: perki.connect.com.au 915738785 29610 203.60.16.6 (7 Jan 1999 19:53:05 GMT) Organization: Customer of Southern Internet Services NNTP-Posting-Date: 7 Jan 1999 19:53:05 GMT Newsgroups: borland.public.jbuilder.java.language