0

In my Java application, I just use two different panels named as Panel1, Panel2. Both panels have their own ChartPanel from JFreeChart to generate dynamic chart. If I want to clear this by using,

    if(Panel1.getComponentCount() != 0) Panel1.remove(Graph.CPanel);
    if(Panel2.getComponentCount() != 0) Panel2.remove(Graph1.CPanel1);
    Panel1.repaint();
    Panel2.repaint();

the above code mean, it just remove panel one content. Panel two still show the chart panel, but that's not running. Why panel two didn't remove its content?

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
A.Mohamed Bilal
  • 115
  • 1
  • 13
  • Please learn common [Java naming conventions](http://java.sun.com/docs/books/jls/second_edition/html/names.doc.html#73307) (specifically the case used for the names) for class, method & attribute names & use them consistently. – Andrew Thompson Jan 24 '14 at 11:20
  • This code is not sufficient to resolve your concern. – Rahul Jan 24 '14 at 11:21
  • For better help sooner, post an [MCVE](http://stackoverflow.com/help/mcve). But do the MCVE using simple colored (JSE) panels first. – Andrew Thompson Jan 24 '14 at 11:21
  • @Rahul Generally best to point the OP to the MCVE/MCTR document at times like this, otherwise we tend to get bits and pieces of uncompilable code snippets. – Andrew Thompson Jan 24 '14 at 11:23
  • @Rahul, then can you give sample code to remocve chartpanel from the jpanel? – A.Mohamed Bilal Jan 24 '14 at 11:44

2 Answers2

2

While you can chose to remove the view component, which requires revalidate(), a better choice is to update the model and let the view respond. Some related examples are cited here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
0
      Panel1.removeAll();
      Panel2.removeAll();

The above statements remove all components in those panels successfully.

A.Mohamed Bilal
  • 115
  • 1
  • 13