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
Andrey Kuznetsov - 29 Dec 2005 21:39 GMT
> 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)

Signature
Andrey Kuznetsov
http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities