EarthWeb
Developer.com
Site
windows 2000
visual c++
java
visual basic
javascripts
recommend it
 
Book
thinking in java
 
Interact
forum
guest book
jobs
jokes
what's new

share code
 
Resource
add resource
modify resource
new resource
 

[Internet Jobs]
-----
Java by E-mail:

Get the weekly e-mail highlights on Java!
-----

-

Selecting a tree node


Author: Zafir Anjum

Selecting a tree node using the row number is pretty straightforward. You simply call setSelectionRow() with the problem row number. The problem with this though is that often times the row is not even visible.

The other function setSelectionPath() is more useful but less intuitive to use. It takes a while to figure out how to get the treepath. Here's a sample code snippet for when we have the tree node.


// node is of the type DefaultMutableTreeNode
tree.setSelectionPath( new TreePath( node.getPath() ) );

// This statement does the exact same thing as that above
// Use one or the other - not both
tree.setSelectionPath( new TreePath( ((DefaultTreeModel)tree.getModel()).getPathToRoot( node ) ) );


Posted On: 23-Jan-1999

internet.commerce



Acceptable Use Policy

JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers