Article View: borland.public.jbuilder.java.swing
Article #10955Re: tree from dataset?
From: Alex Humphreys
Date: Wed, 21 Jul 1999 00:00
Date: Wed, 21 Jul 1999 00:00
82 lines
3620 bytes
3620 bytes
Thanks! Helpful! But I'm still kind of confused how GraphModel and TreeModel
hook up to a TreeControl. Could you post or email me an explanation or some
source code that covers how the one interacts with the other.
thank you very much.
Alex
Tad Frysinger wrote:
> In article <37837FF6.654DDC32@sema4.com>, ahumphreys@sema4.com says...
> > What is the best way to populate a java tree from a dataset (or just on
> > the fly)? I don't know how many nodes we're going to have, so I can't
> > really set up the appropriate number of GraphLocations in the code -- it
> > needs to be done dynamically. Thanks. -alex
> >
> >
> Loop through the dataset, grab the info you need and build the tree.
> Here is a fragment where I am adding database metadata (column
> information) to a tree that describes a database table.
>
> while (rsColumnList.next())
> {
> // Now add a description for this particular column
> columnDescNode = new DefaultMutableTreeNode(
> new Pair( imageCol,
> rsColumnList.getString( "COLUMN_NAME" )));
> treeModel.insertNodeInto( columnDescNode,
> columnsNode,
> columnsNode.getChildCount() );
> }
>
> The DefaultMutableTree node takes an object that it stores in its
> 'userObject' instance variable. This is usually a string, but in my
> example I am using a JGL Pair object. This means I also need to have a
> renderer assigned to my tree that knows how to get into that Pair()
> object and update a renderer component appropriately:
>
> class PairTreeCellRenderer extends DefaultTreeCellRenderer
> {
>
> public void PairTreeCellRenderer()
> {
>
> setLeafIcon( null );
> setClosedIcon( null );
> setOpenIcon( null );
>
> }
>
> 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 );
> pair = (Pair) ((DefaultMutableTreeNode)value).getUserObject();
> setText( pair.second.toString() );
> setIcon( (Icon)pair.first );
> selected = sel;
> return this;
> }
>
> public String getToolTipText()
>
> {
>
> return "";
>
> }
> private Pair pair;
> }
>
> Tad Frysinger (TeamB)
Technical Details
Message-ID:
<37963316.9942AF68@optonline.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<37837FF6.654DDC32@sema4.com> <MPG.11ed7e74854d8b90989a42@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,1bbafc452ff20417 X-Google-Attributes: gid111d45,public From: Alex Humphreys <ahum@optonline.net> Subject: Re: tree from dataset? Date: 1999/07/21 Message-ID: <37963316.9942AF68@optonline.net> X-Deja-AN: 503678400 Content-Transfer-Encoding: 7bit References: <37837FF6.654DDC32@sema4.com> <MPG.11ed7e74854d8b90989a42@forums.borland.com> To: Tad Frysinger <tfrysinger@earthlink.net> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: Another Netscape Collabra Server User Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing