Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change panels content

Status
Not open for further replies.

Dijkstra30

Programmer
Oct 24, 2005
13
0
0
RO
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.

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?
 
Keep a reference to the JScrollPane on the right, say scrollPane, and do something like the following when the content needs to change. You may need to do a revalidate on the scrollPane too.
Code:
scrollPane.getViewPort().add( [i]new content[/i] );

Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top