Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTree/JScrollpane problem

 
Jerry Crothers
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having a problem using the JTree when using a scroll pane.

Basically after clicking on a child node (under the root) the nodes below that expand, however the scroll bar appears and moves down slightly, so that the child node (of the root) is at the top of the window. The root node is hidden now.

Now when I click to collapse the nodes of the child node (of the root) - ie the first line at the top of the window, this code:

int x = e.getX();
int y = e.getY();
int row = tree.getRowForLocation(x, y);
TreePath path = tree.getPathForRow(row);
TreeNode node = (TreeNode)path.getLastPathComponent();

returns row Zero and the node is the root node (which was actually hidden).

It should be returning row = -1 and then just collapse the tree. Instead the click event on the root node occurs.

Please help......

Jerry.
 
Jerry Crothers
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry typo on this line:

Now when I click to collapse the nodes of the child node (of the root) - ie the first line at the top of the window, this code:

Should be:

Now when I click to collapse the nodes of the child node (UNDER the root) - ie the first line at the top of the window, this code:

Jerry.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic