Scrollbar Moving Automatically on Tree Expansion - in Java Swing's BasicTreeUI

N

naimish.parikh

Hi ,

My Problem:
When a tree item/row is expanded , the scrollbars of the tree
automatically move to ensure that the child of the tree item (which is
expanded) is visible.
I donot want the scrollbars to move when tree is expanded. Is there
any way we can do it without extending/inheriting
javax.swing.plaf.basic.BasicTreeUI?

I use:
- Java Swing's MetalTreeUI and my own tree class derived from JTree.

This behaviour seems to be controlled by
BasicTreeUI.toggleExpandedState

/**
* Expands path if it is not expanded, or collapses row if it is
expanded.
* If expanding a path and JTree scrolls on expand,
ensureRowsAreVisible
* is invoked to scroll as many of the children to visible as
possible
* (tries to scroll to last visible descendant of path).
*/
protected void toggleExpandState(TreePath path) {
if(!tree.isExpanded(path)) {
int row = getRowForPath(tree, path);

tree.expandPath(path);
updateSize();
if(row != -1) {
if(tree.getScrollsOnExpand())
ensureRowsAreVisible(row, row + treeState.
getVisibleChildCount(path));
else
ensureRowsAreVisible(row, row);
}
}
else {
tree.collapsePath(path);
updateSize();
}
}




Thanks
Naimish Parikh
 
A

Andrey Kuznetsov

if(tree.getScrollsOnExpand())
ensureRowsAreVisible(row, row + treeState.
getVisibleChildCount(path));

as you can see from this code snippet that you can control it with
JTree#setScrollsOnExpand(false)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,814
Latest member
SpicetreeDigital

Latest Threads

Top