Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to make JPanel redraw its children correctly ?  RSS feed

 
Slavko Perevalov
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!
I have the problem with children redrawing after adding to container dynamically.
Main idea is the following: i need to create diagram editor having panel with list of selected object's properties on the riht side. I'd like to display different panels for different types of objects. So when new object is selected i want to remove old properties panel and add new one. The problem is that when new panel is added its child components (labels, textfields etc) aren't redrawn at all until the whole frame will be resized. For testing i used the following code:

JButton button = new JButton("remove");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
rightToolbarPanel.removeAll();
rightToolbarPanel.revalidate();
Diagram.this.repaint();
}
});
toolbar.add(button);

JButton button2 = new JButton("add");
button2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {
PropertiesPanel panel = new PropertiesPanel();
rightToolbarPanel.add(panel);
rightToolbarPanel.getLayout()
.layoutContainer(rightToolbarPanel);
Diagram.this.repaint();
}
});
toolbar.add(button2);

Thus with this buttons theoretically user can remove or add new panel. But in practice only removal works correctly. When "Add" button is pressed I see that new panel was added to the right side, but its subcomponents aren't visible.

Diagram has layout set to BorderLayout and rightToolbarPanel was added using BorderLayout.SOUTH constraint. PropertiesPanel subclassed from JPanel.

Could anybody suggest me solution how to make added panel repaint itself completely including all subcomponents ?
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just another cross poster.
http://forums.sun.com/thread.jspa?threadID=5362214
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Slavko,

Please Use Code Tags, and Be Forthright When Cross Posting To Other Sites.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!