Is there any way to prevent the scrolling from happening? I have tried
the following, and it didn't work:
public class TreeFrame extends JPanel implements
TreeExpansionListener
{
JTree mTree;
JScrollPane mScroller;
private void init() {
.......
mTree = new JTree();
.......
mScroller = new JScrollPane(mTree);
add(mScroller);
}
// Called when a node in the tree is expanded
public void treeExpanded(TreeExpansionEvent event) {
// do stuff
........
// readjust the horizontal scrollbar
JScrollBar hScrollBar = mScroller.getHorizontalScrollBar();
hScrollBar.setValue(0);
hScrollBar.revalidate();
mScroller.revalidate();
}
}
Thanks!
Katia
: Is there any way to prevent the scrolling from happening? I have tried
I haven't used it, but I've noticed the method
JTree.setScrollsOnExpand(boolean). It looks like
it will stop the vertical scrolling on expansion too.
If this is undesirable, you'll probably have to overload
BasicTreeUI.ensureRowsAreVisible() (assuming you're using
the Basic L&F).
When I had this problem, I just increased my JDialog's size
so that the JTree would always fit horizontally.
-troy
I have found this filed as a bug in Bug Parade at:
http://developer.java.sun.com/developer/bugParade/bugs/4133514.html
Unfortunately, they don't offer any work-arounds.
You mentioned overloading methods on BasicTreeUI. Will changing that class
affect the portability of my code?
Thanks,
Katia
: Thanks a lot for the advice!
: However, I have to use JFC 1.0.3 since I need to support JDK 1.1.6. and the
: method JTree.setScrollsOnExpand(boolean) does not exist in Swing 1.0.3.
: I have found this filed as a bug in Bug Parade at:
: http://developer.java.sun.com/developer/bugParade/bugs/4133514.html
: You mentioned overloading methods on BasicTreeUI. Will changing that class
: affect the portability of my code?
Portability to other machines? No.
It would affect portability to other versions of Swing, since
the L&F has been changing a lot.
And it will affect your ability to change L&Fs on the fly,
since you'd have to chose which one(s) to subclass.
Actually, since you're working with Swing 1.0.3, I wouldn't
recommend L&F work, since it was modified heavily in the
later versions. You could consider Swing 1.1 Beta 2.
In any case, this is starting to be a lot of work for a
relatively small behavior tweek. Maybe you could catch
the expansion event and scroll it back.
-troy
JTree tree = new JTree() {
public void scrollRectToVisible(Rectangle contentRect) {
contentRect.width = 1;
super.scrollRectToVisible(contentRect);
}
};
Good luck.
Daniel Leuck
d...@pretium.com
----------------------------------------------------------------------------------------
Katarina Obradovic wrote:
> Can anyone help with the following problem:
> I have a Jtree inside a JScrollPane. The nodes of the JTree are pretty
> long, so every time a node is expanded, the scrollpane scrolls
> automatically to the right (trying to expose the children of the
> expanded node)
>
> Is there any way to prevent the scrolling from happening? I have tried