🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #79

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

#79
From: naimish.parikh
Date: Thu, 29 Dec 2005 18:23
50 lines
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
Technical Details
Message-ID: <1135880592.127419.75950@g49g2000cwa.googlegroups.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!g49g2000cwa.googlegroups.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 111d45,82e8bb0d2517a790,start
X-Google-Thread: 10a146,82e8bb0d2517a790,start
X-Google-Thread: 113ae9,82e8bb0d2517a790,start
X-Google-Attributes: gid111d45,gid10a146,gid113ae9,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!g49g2000cwa.googlegroups.com!not-for-mail
From: naimish.parikh@gmail.com
Newsgroups: borland.public.jbuilder.java.swing,comp.lang.java.programmer,comp.lang.java.help
Subject: Scrollbar Moving Automatically on Tree Expansion - in Java Swing's BasicTreeUI
Date: 29 Dec 2005 10:23:12 -0800
Organization: http://groups.google.com
Lines: 51
Message-ID: <1135880592.127419.75950@g49g2000cwa.googlegroups.com>
NNTP-Posting-Host: 171.71.137.163
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1135880597 16109 127.0.0.1 (29 Dec 2005 18:23:17 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Thu, 29 Dec 2005 18:23:17 +0000 (UTC)
User-Agent: G2/0.2
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322),gzip(gfe),gzip(gfe)
Complaints-To: groups-abuse@google.com
Injection-Info: g49g2000cwa.googlegroups.com; posting-host=171.71.137.163;
   posting-account=_7sdKQ0AAAASIuN_MrktXfNFD6-NUS0D