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:
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();
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).
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.
I have also handled the componentResized
listener of the depictorPanel to invalidate and repaint the viewer, but no luck.