Skip to main content

How do I find out the selected node in a JTreeTable

6 replies [Last post]
Anonymous

Hi!

If the user selects a row in a JTreeTable, how do I find out which node
he/she actually selected?

--
Greets,
Robert F. Beeger
____________________________________
| |
| Robert F. Beeger |
| e-mail : robert@beeger.net |
| web-site : http://beeger.net |
|____________________________________|

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
rameshgupta
Offline
Joined: 2004-06-04

> If the user selects a row in a JTreeTable, how do I
> find out which node
> he/she actually selected?

This is a hole in the api. JTreeTable has a private TreeTableCellRenderer renderer member. This is the tree whose selection model should be queried to determine the selected row. I just filed Issue 41 to expose the tree selection model from JTreeTable.

Ramesh

rbeeger
Offline
Joined: 2004-07-27

Thanks.
Cannot wait for the fix.

rameshgupta
Offline
Joined: 2004-06-04

> Thanks.
> Cannot wait for the fix.

I just put it in ;-)
To find out the selected node you may use the following as a starting point:

TreeSelectionModel tsm;
tsm = treeTable.getTreeSelectionModel();
tsm.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent ev) {
TreePath[] paths = ev.getPaths();
for (int i=0; i < paths.length; i++) {
System.out.println(paths[i] +
(ev.isAddedPath(paths[i]) ?
" was selected" : " was deselected"));
}
}
});

Ramesh

rbeeger
Offline
Joined: 2004-07-27

Thanks!
Will try it out in the next days.

rbeeger
Offline
Joined: 2004-07-27

It took me some time, but finally I found the time to check out the current CVS version. Looks good and works good. Thanks!

siva
Offline
Joined: 2003-07-15

Interesting. I have been using

getSelectionModel().getAnchorSelectionIndex()

on the treetable and it worked for me.