Thread View: borland.public.jbuilder.java.swing
2 messages
2 total messages
Started by naimish.parikh
Thu, 29 Dec 2005 18:23
Scrollbar Moving Automatically on Tree Expansion - in Java Swing's BasicTreeUI
Author: naimish.parikh
Date: Thu, 29 Dec 2005 18:23
Date: Thu, 29 Dec 2005 18:23
50 lines
2583 bytes
2583 bytes
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
Re: Scrollbar Moving Automatically on Tree Expansion - in Java Swing's BasicTreeUI
Author: Andrey Kuznetsov
Date: Thu, 29 Dec 2005 21:39
Date: Thu, 29 Dec 2005 21:39
12 lines
1628 bytes
1628 bytes
> 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) -- 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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads