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.