Re: Advanced: Populating, Printing Tree Structure
From: Steve Johnson (sjohnson_at_oberon.com)
Date: 02/21/04
- Next message: John: "Re: Teaching some Newbies: Advice please..."
- Previous message: Dr. Mercury: "Re: Anyone for a small Java challenge?"
- In reply to: Barry White: "Re: Advanced: Populating, Printing Tree Structure"
- Next in thread: Barry White: "Re: Advanced: Populating, Printing Tree Structure"
- Reply: Barry White: "Re: Advanced: Populating, Printing Tree Structure"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 21 Feb 2004 15:18:35 -0600
Barry White wrote:
>
> Hi Steve,
>
> have you looked at the javax.swing.tree package. I know it's not a
> swing application but the tree model framework is already in place, no
> need to reinvent the wheel.
>
> DefaultTreeModel
> DefaultMutableTreeNode
Yes, I have looked into those APIs, but still couldn't figure out how to
use them to any advantage with a recursive algorithm. If you have an
example of using those APIs for my scenario, that would be great.
> From a general design point of view you could make better use of the
> Collections framework:
[snip]
> SUGGESTION:
>
> public Node findNode( Integer nodeID, Collection nodeList )
> {
> Iterator iter = nodeList.iterator();
> while (iter.hasNext())
> {
> Node node = (Node)iter.next();
> Map dataRow = (Map)node.getObject();
> Integer currID = (Integer)dataRow.get("ID");
>
> if( nodeID.equals(currID) )
> {
> return node;
> }
>
> findNode( nodeID, node.getChildList() );
> }
>
> return null; //couldn't find node
> }
Thanks, this sounds like a good idea.
The primary obstacle is still populating and printing that tree, and I'm
completely stuck.
- Next message: John: "Re: Teaching some Newbies: Advice please..."
- Previous message: Dr. Mercury: "Re: Anyone for a small Java challenge?"
- In reply to: Barry White: "Re: Advanced: Populating, Printing Tree Structure"
- Next in thread: Barry White: "Re: Advanced: Populating, Printing Tree Structure"
- Reply: Barry White: "Re: Advanced: Populating, Printing Tree Structure"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|