Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem: painting a tree structure recursively

0 views
Skip to first unread message

rfr...@my-deja.com

unread,
May 17, 2000, 3:00:00 AM5/17/00
to
First: I cannot use swing.jtree since I have to use the awt of jdk1.1.7.

I have a problem with painting a tree structure recursively.
My tree structure is very similar to the hierarchy
of folders in the MS Windows NT Explorer.

The problem is that I cannot figure out how to increment correctly the
y variable.
In the code I attached below y is a local variable.
But this not the correct solution since y gets its former value
when coming back from a recursion loop.

On the other using a class variable does not help me in the present case
since it would be incremented with every repaint of the tree structure.

Here is the piece of code:

private void paintTreeItem( AlbumTreeViewItem item, int x, int y)
{
// painting the item
item.setBounds( x, y, 256, 20 );
}

public void paintTreeItems( Hashtable hashTreeViewItems, int iHash,
int x, int y )
{


AlbumTreeViewItem item = null;
item = (AlbumTreeViewItem)hashTreeViewItems.get(new
Integer(iHash));


x = x + 10;

paintTreeItem( item, x, y );

Vector vector = item.getAllChilds();
Enumeration enumeration = vector.elements();

while ( enumeration.hasMoreElements() )
{
y = y + 24;

AlbumTreeViewItem jtem =
(AlbumTreeViewItem)enumeration.nextElement();
int jHash = jtem.getHash();
paintTreeItems( hashTreeViewItems, jHash, x, y );//recursive
call
}
}


Sent via Deja.com http://www.deja.com/
Before you buy.

0 new messages