🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #8458

Re: JTree

#8458
From: Torsten Welches
Date: Fri, 23 Mar 2001 08:49
49 lines
2149 bytes
Mike,

you would have to provide a small (inner) helper class and put 
an instance of this into your DefaultMutableTreeNodes.
Here's some untestet code:

class DBData {
  public String kapitelName;
  public int kapitelID;
  public DBData(String name, int id) {
    kaptelName = name;
    kapitelID = id;
  }
  //this will be displayed
  public String toString() {
    return kapitelName + " " + kapitelID;
  }
}

put it in like this:
DBData data = new DBData(queryDataSet2.getString(2) queryDataSet2.getInt(3));
.. new DefaultMutableTreeNode(data);

retrieve ID like this:
DefaultMutableTreeNode node = ...
DBData data = (DBData)node.getUserObjject();
int id = data.kapitelID;

Torsten

dhj <mkr@cos.de> wrote:
>Hi,
>
>Does anyone have a working example of how can I save a pointer
>form every Item in the tree ?
>
>For example:  I have a three with one level  and I want to get the
>ID from the Database when I click the Item.
>At the moment I fill the Tree like that:
>
>              kapitel = queryDataSet2.getString(2) + " " +
>queryDataSet2.getInt(3);
>
>              child1 = new DefaultMutableTreeNode(kapitel);
>              node1.add(child1);
>
>and get only the text of the Database but not the ID.
>So who can tell me how I can do that
Technical Details
Message-ID: <3abb0e1f$2_1@dnews>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!news.stealth.net!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!dnews!207.105.83.65
References: <3ABA7B79.ABA8A4AC@cos.de>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,24d622f04a234c0
X-Google-Attributes: gidf74b3,public
X-Google-ArrivalTime: 2001-03-23 04:06:06 PST
From: "Torsten Welches" <torsten.welches@who.cares.netcologne.de>
Sender: "Torsten Welches" <torsten.welches@who.cares.netcologne.de>
Reply-To: "Torsten Welches" <torsten.welches@who.cares.netcologne.de>
Subject: Re: JTree
Newsgroups: borland.public.jbuilder.java.language
X-User-Info: 193.158.55.74 193.158.55.74    
References:  <3ABA7B79.ABA8A4AC@cos.de> 
NNTP-Posting-Host: 207.105.83.65
Message-ID: <3abb0e1f$2_1@dnews>
Date: 23 Mar 2001 00:49:35 -0800
X-Trace: 23 Mar 2001 00:49:35 -0800, 207.105.83.65
Lines: 51
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!news.stealth.net!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!dnews!207.105.83.65