1

I've got a project in Java where I have a frame which is divided in 2 panels. The left panel consists of a JTabbedPane and the right panel of a JTree. These are 2 different classes. Now if I doubleclick on a item in the Jtree, I want the tabbed pane to switch to the tab about the node I pressed on and fill in the data.

For example when I press on a student, I want to jump to the student tab and fill in the details I can get out of the tree, name etc.

I know you can use a selection listener with the tree and use the setindexat for the tabs, but my biggest problem is I don't know how the classes can communicate with eachother. Does anybody have a idea?

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
B13ZT
  • 237
  • 3
  • 4
  • 11

2 Answers2

1

You should write an interface for a listener and make your tabbed pane implement that listener. The listener will basically listen to events generated by the tree. So have your tree also fire events whenever a double click is done on a particular item.

In the implementation of the listener, look for the child that is the item associated with that event and do your processing i.e. populate the tab.

SomeDude
  • 13,876
  • 5
  • 21
  • 44
1

In your TreeSelectionListener, illustrated here, invoke setSelectedIndex() or setSelectedComponent(), discussed here, to select the tab corresponding to the selection. A Map<TreeNode, Integer> or Map<TreeNode, Component> may simplify identifying the correct tab.

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