Skip to content
Advertisement

Java AWT Window doesn’t get repainted

I’ve derived a class from window, but whenever I call setValue() (which calls repaint) it doesn’t get redrawn (the method is called, but nothing changes on the screen). The first value is drawn, which is 0 by default. Here’s the class:

JavaScript

Why does it not get repainted properly?

Advertisement

Answer

From the oracle docs

If [the update] method is reimplemented, super.update(g) should be called so that lightweight components are properly rendered. If a child component is entirely clipped by the current clipping setting in g, update() will not be forwarded to that child.

Also, call super.paint(g) in paint() just as the first commenter said.

If it still doesn’t work, you should use Swing, like a JComponent instead of window.

JavaScript
Advertisement