Reputation: 2953
I have a JTree on the left side of the frame. Each node in the tree has a corresponding panel that is to be displayed on the right side as the user clicks that node. It is not the same panel that is displaying different data. It can be entirely different panels. What is the best way to do this?
Upvotes: 1
Views: 230
Reputation: 36611
See my answer on another SO question, which illustrates how to change the contents of a panel based on the selection in a JList
and shows how to use a CardLayout
.
Combine that sample code with the Swing JTree
tutorial and a reference to the TreeSelectionListener
interface (which is the equivalent of the ListSelectionListener
which I used in my answer since that code uses a JList
instead of a JTree
) and you should be able to complete your requirement.
Upvotes: 1