Daniel Rivera Guzman
Daniel Rivera Guzman

Reputation: 13

How can i put a JList object in a Jtree node in Java Swing?

I have this doubt, i'm using java swing, and i need to do a data tree that need display a Jlist content of a node of Jtree.

Each one in different JPanel

Upvotes: 0

Views: 757

Answers (1)

trashgod
trashgod

Reputation: 205885

For the reasons suggested here, you'd need a custom TreeCellRenderer and TreeCellEditor for your JTree.

As a less complex alternative, add a TreeSelectionListener to your tree. In the listener, update the ListModel of an adjacent JList to reflect the current tree selection. Use a GridLayout(1, 0) for the tree and list, as shown in this related example using JTable and JList.

Upvotes: 2

Related Questions