Pergunta

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?

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top