Skip to main content

How to get double-clicked JXTreeTableNodes?

5 replies [Last post]
TomTree
Offline
Joined: 2012-01-31
Points: 0

Hello, I've got a question about JXTreeTables. I want a window, showing some information about the node, to pop up, when a node is double-clicked. Now, is it possible to get the double-clicked node of the JXTreeTable or null if the click wasn't directly on a node?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
TomTree
Offline
Joined: 2012-01-31
Points: 0

Hi there,

thanks for your answers and sorry for the delay. I've now tested the two solutions and Karl's worked just fine. I don't know if I'm missing something but I can't see any advantages in your code, Jeanette. I will also post it on StackOverflow but I will wait for your feedback before I mark it as answer.

Thanks again!

kleopatra
Offline
Joined: 2003-06-11
Points: 0

the difference is between firing on a click _anywhere in the table cell_ containing the node  vs. _directly on the node_ Me  assuming you were after the latter - which should be supported by treeTable api :-)

Cheers

Jeanette

 

TomTree
Offline
Joined: 2012-01-31
Points: 0

Oh okay, maybe I should've precised my question a bit concerning this aspect :D. I was talking about a click anywhere and have the answer now, thanks for your effort :)!

kleopatra
Offline
Joined: 2003-06-11
Points: 0

just noticed this duplicate of your post on SO (or the other way round, don't know and don't care :-) 

stackoverflow.com/questions/9059093/how-to-get-a-double-clicked-treetablenode

Assuming you mean the behaviour of tree.getRowForLocation(...): there is no api on the treeTable, you hit missing api and might consider to file an improvement issue in the swingx issue tracker :-)

SO has a code-snippet of a workaround (never managed to make code readable here, unwilling to try again ;-)

HTH

Jeanette

 

kschaefe
Offline
Joined: 2006-06-08
Points: 0

Nodes are not part of the display hierarchy, so you would need to add a MouseListener to the JXTreeTable:

public void mouseClicked(MouseEvent e) {
    if (SwingUtitlities.isLeftMouseButton(e) && e.getClickCount() == 2) {
        TreePath path = treeTable.getPathForRow(treeTable.rowAtPoint(e.getPoint));
        //... do stuff with path, such as extract current node
    }
}

Karl