I am trying to understand why my JComponent is updated when I manually drag my window, but it does not update when I call redraw or re-evaluate. The data is ready for display, but it just won’t be displayed until I manually resize it. Can anyone give any suggestions on what I can do, or does it sound like it is not a problem with Swing since I tried redrawing and revalidate?
One weird thing I noticed is that if I have this code:
sp.setSize(sp.getSize().width, sp.getSize().height+1);
sp.setSize(sp.getSize().width, sp.getSize().height-1);
If the first line is used, then JComponent will be updated. If I do not use either or both of these lines, it will not, which seems strange to me.
Basically, I just put the JPanel in a JInternalFrame in JDesktopPane. There are two main functions for what I am trying to do. One adds a new JPanel, and the other tries to update it so that new data is displayed:
public void addNewSP()
{
sp = new JInternalFrame("SP");
sp.setClosable(true);
sp.setLocation(700, 400);
sp.setResizable(true);
sp.add(popUp);
this.parentContainer.add(sp, JLayeredPane.DRAG_LAYER);
sp.pack();
sp.show();
sp.setSize(500, 500);
sp.setPreferredSize(new Dimension(500, 500));
}
public void refreshSP()
{
sp.repaint();
sp.validate();
sp.repaint();
sp.validate();
parentContainer.validate();
parentContainer.repaint();
sp.setSize(sp.getSize().width, sp.getSize().height+1);
sp.setSize(sp.getSize().width, sp.getSize().height-1);
}
}
BTW's potential parent is JDesktopPane
source
share