2

To prevent a JTree node from collapsing, you can use the setExpandedState() method.

I dont see a similar method for the SwingX JXTreeTable class, and it seems that JXTreeTable doesnt extend JXTree (which extends JTree).

Any suggestions as to how I can prevent a root node from collapsing on a JXTreeTable?

miken32
  • 42,008
  • 16
  • 111
  • 154
Swoop
  • 514
  • 5
  • 17

1 Answers1

5

You may add tree-will-expand listener with addTreeWillExpandListener() to prevent a tree node from expanding or collapsing.

For example to prevent collapsing:

treeTable.addTreeWillExpandListener(new TreeWillExpandListener() {
    public void treeWillExpand(TreeExpansionEvent e)
            throws ExpandVetoException {
    }

    public void treeWillCollapse(TreeExpansionEvent e)
            throws ExpandVetoException {
        throw new ExpandVetoException(e);
    }
});

See How to Write a Tree-Will-Expand Listener for some examples.

JXTreeTable also has a set of methods for collapsing and expanding tree nodes: expandPath(), expandAll(), collapsePath() and collapseAll(). Maybe these can be helpful.

tenorsax
  • 21,123
  • 9
  • 60
  • 107