Article View: borland.public.jbuilder.java.swing
Article #11496Re: JTree of objects other than String but displaying String, possible?
From: Michael Härtig
Date: Thu, 27 May 1999 00:00
Date: Thu, 27 May 1999 00:00
51 lines
2097 bytes
2097 bytes
Hi,
Jabber schrieb:
>
> I am trying to create a JTree of my own defined objects, rather than
> Strings. This in itself is easy:
> child = new DefaultMutableTreeNode(new MyObject);
> parent.add(child);
> However, I would like to see a String attribute of MyObject as the label
> for the node in the tree, rather than the MyObject.toString(); of it. Is
> there a way to do this?
Yes. Build your own class and override "toString()":
public class MyMutableTreeNode extends DefaultMutableTreeNode{
Object myObject;
public MyMutableTreeNode(Object aObject){
super(aObject);
myObject = aObject;
}
public String toString(){
return myObject.THE RETURN STRING YOU WANT;
}
}
you use it just like a DefaultMutableTreeNode:
child = new MyMutableTreeNode(new MyObject);
parent.add(child);
Hope this helps...
Michael
--
////
(o o)
+-----ooO--(_)--Ooo---------------------------------------+
| |
| Michael H�rtig Neumann & Partner |
| Informationssysteme GmbH |
| Softwareentwicklung An der Hohen Stra�e 1 |
| 08393 Meerane |
| |
+------------Oooo-----------------------------------------+
oooO ( )
( ) (_)
(_)
Technical Details
Message-ID:
<374CF245.64E2A84A@nupis.de>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<374C580D.635E4D78@tiac.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: 111d45,7b988e188e65d939 X-Google-Attributes: gid111d45,public From: Michael Härtig <haertig@nupis.de> Subject: Re: JTree of objects other than String but displaying String, possible? Date: 1999/05/27 Message-ID: <374CF245.64E2A84A@nupis.de> X-Deja-AN: 482627387 Content-Transfer-Encoding: 8bit References: <374C580D.635E4D78@tiac.net> X-Accept-Language: de Content-Type: text/plain; charset=iso-8859-1 Organization: Another Netscape Collabra Server User Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing