0

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

  • 1
    Your question is not clear. Also, please post the code you tried and tell us what it's doing wrong. See [MCVE](http://stackoverflow.com/help/mcve). – user1803551 Sep 28 '14 at 00:15
  • 1
    It's gonna be tricky. Both JTrees and JLists work using a Component Renderer. This renderer is used to draw list / tree elements, but isn't actually added to the GUI, so event capture / element selection would need to be customized in your situation – ControlAltDel Sep 28 '14 at 00:19

1 Answers1

2

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.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045