title: Component in JPanel gone automatically
body: <p>I have a JPanel and a Jlist, when the user selects a different item in the list, the corresponding component will be added to the panel, while the previous component will be removed. Here is the portion of the code:</p>
  
  <pre><code>depictorPanel.removeAll();
  depictorPanel.invalidate();
  depictorPanel.repaint();
  GridBagConstraints constraints = new GridBagConstraints();
  constraints.fill = GridBagConstraints.BOTH;
  depictorPanel.add(viewer, constraints);
  viewer.setSize(depictorPanel.getSize());
  depictorPanel.invalidate();
  depictorPanel.repaint();
  </code></pre>
  
  <p>where the depictorPanel is the JPanel, and the viewer is the component (btw. the viewer is of type VisualizationView coming from the JUNG library, which inherits also JPanel). </p>
  
  <p>When I resize the JPanel (done by resizing the whole window, such that all the components in the window are resized), or minimize the window and restore it, the viewer component is gone, I can tell since I set different background colors of the depictorPanel and the viewer.</p>
  
  <p>I have also handled the <code>componentResized</code> listener of the depictorPanel to invalidate and repaint the viewer, but no luck.</p>