Darin Beaudreau
Darin Beaudreau

Reputation: 391

JPanel repaint() call not working

I feel as though the solution to this is very simple and I'm just overlooking something stupid, but I can't seem to make the repaint() method of one of my JPanels work. The JPanel in question is a member object of another class which handles all the logic behind what is drawn to the JPanel, however, whenever I call repaint() in my thread, I do not see anything drawn, nor do I see my System.out.println() call, which I put in there for debugging purposes. I have put the files on Github for convenience. Here are the three files I think MIGHT have something to do with it. You can always look at the others if you need to.

SageLife.java

LifeFramework.java

Grid.java

I've created plenty of JPanels before and have rarely encountered this problem, so I'm just not sure what's causing it.

Upvotes: 0

Views: 613

Answers (1)

Reimeus
Reimeus

Reputation: 159754

You are overriding paintComponents rather than paintComponent in your Grid JPanel. This does not follow Swing's paint chain mechanism.

@Override
public void paintComponents(Graphics g) {
    super.paintComponents(g);

Note: always go for Swing Timer over Thread for handling UI updates in Swing.

Upvotes: 3

Related Questions