javaswingswingxjxtreetable

How to get a double-clicked TreeTableNode?


I'm working with Eclipse and 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?


Solution

  • I've received an answer on the thread kleopatra mentioned which works perfectly fine and is simplier. Here is the code:

    treeTable.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(final MouseEvent e) {
            if (e.getClickCount() != 2) {
                return;
            }
    
            final int rowIndex = treeTable.rowAtPoint(e.getPoint());
    
            if (rowIndex < 0) {
                return;
            }
    
            final TreeTableNode selectedNode = (TreeTableNode)treeTable.getPathForRow(rowIndex).getLastPathComponent();
        }
    });