File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JTree/JScrollpane problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTree/JScrollpane problem" Watch "JTree/JScrollpane problem" New topic
Author

JTree/JScrollpane problem

Jerry Crothers
Ranch Hand

Joined: Mar 06, 2001
Posts: 34
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

Joined: Mar 06, 2001
Posts: 34
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTree/JScrollpane problem
 
Similar Threads
Searching a JTree
Expanding a Specific Node in JTree
Subtree in JTree
JTree + JList in JScrollPane - Out of Sync
XML to DOM to JTree