Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / December 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
naimish.parikh@gmail.com - 29 Dec 2005 18:23 GMT
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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.