Re: Advanced: Populating, Printing Tree Structure

From: Steve Johnson (sjohnson_at_oberon.com)
Date: 02/21/04


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.



Relevant Pages

  • Re: Advanced: Populating, Printing Tree Structure
    ... > swing application but the tree model framework is already in place, ... > DefaultTreeModel ... Yes, I have looked into those APIs, but still couldn't figure out how to ...
    (comp.lang.java.developer)
  • Re: Advanced: Populating, Printing Tree Structure
    ... > swing application but the tree model framework is already in place, ... > DefaultTreeModel ... Yes, I have looked into those APIs, but still couldn't figure out how to ...
    (comp.lang.java.programmer)