Dijkstra30
Programmer
I am trying to build a panel like this:
- it contanins a JSplitPane
- at the left I have a tree - list of employees
- at the right I have a panel which displays a "dialog" depending on the three selection - info about employees.
I want to replace that dialog with a new created one for the employee selected everytime the selection changes.
I tryed rebuilding the whole frame. I works but I just want to rebuild the right panel somehow so the tree expansion remains the same
How can i change the RightPanel content without rebuilding the whole frame?
- it contanins a JSplitPane
- at the left I have a tree - list of employees
- at the right I have a panel which displays a "dialog" depending on the three selection - info about employees.
I want to replace that dialog with a new created one for the employee selected everytime the selection changes.
Code:
public JComponent buildMainPanel(Employee employee) {
[RED]rightPane = new JScrollPane(buildRightPanel(employee)); [/RED]
leftPane = new JScrollPane(buildTree());
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
leftPane, rightPane);
splitPane.setDividerLocation(150);
Dimension minimumSize = new Dimension(20, 50);
leftPane.setMinimumSize(minimumSize);
rightPane.setMinimumSize(minimumSize);
return splitPane;
}
Code:
private JComponent buildRightPanel(Employee employee) {
dialog = new EditSportDialog(employee);
return dialog.buildContentPane();
}
I tryed rebuilding the whole frame. I works but I just want to rebuild the right panel somehow so the tree expansion remains the same
Code:
public void valueChanged(TreeSelectionEvent event) {
if (tree.getLastSelectedPathComponent() == null) return;
String selection = tree.getLastSelectedPathComponent().toString();
System.out.println("The new selection is: " + selection);
Employee = getEmployee(selection);
f.getContentPane().removeAll();
f.getContentPane().add(mp.buildMainPanel(employee));
f.pack();
f.setVisible(true);
}
How can i change the RightPanel content without rebuilding the whole frame?