Jophin Joseph
Jophin Joseph

Reputation: 2953

How to manipulate a set of panels as the user navigates through a tree view?

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

Answers (2)

Robin
Robin

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

cdeszaq
cdeszaq

Reputation: 31280

Use CardLayout to "flip" the panel that is being displayed.

Upvotes: 4

Related Questions