I've got a problem with Swing, I'm trying to understand how the paintComponent works and I just don't get why in this case it gets called twice or even thrice (it seems to be randomly called to me).
package paintComponentTest;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class UI {
public static void main(String[] args) {
JFrame testFrame = new JFrame();
TestPanel testPanel = new TestPanel();
testFrame.setContentPane(testPanel);
testFrame.setSize(500, 500);
testFrame.setVisible(true);
}
}
class TestPanel extends JPanel {
@Override
public void paintComponent(Graphics g) {
System.out.println("Called");
}
}
I'm working on a different project and my paintComponent also gets called several times whereas I'd like it only to be called once and it prevents me from going forward.
Thanks in advance !