Java repaint not updating

20-Nov-2019 22:32

The paint() method is called by the JVM implicitly in two circumstances.

One is when the first time frame is created and displayed.

To avoid this and to make Java as a robust language, the designers do not allow to call paint() directly.

It seems that there are many types of GUI application that need to have bleeding performance in a mission-critical system.

The other is when the frame is resized (by dragging the frame border with mouse) by the user.

If the programmer would like to call the paint() method in the middle of the coding, he is permitted to call repaint() method.

In many cases, outside of construction, a UI doesn't have that much to go wrong -- and if it does, a simple UI call to 'refresh the whole window' is more than sufficient to get it to update the display.

java repaint not updating-6java repaint not updating-44

What Swing Utilities does is to enque a request (in the form of a object, since Java doesn't have anything nice like code blocks) into the single 'Event Queue' thread.

So, basically, if you're using a multi-threaded system, you're safe if you use this queue.

Of course, if you want to limit yourself to a few tens of updates per second, you can use this approach.

But for heavy systems, where timely updates of data is critical, then pretty much ignore everything you've read about Swing threading before.

Optimisation tricks: It's a shame that multi-threaded access is one of the less well understood parts of Java, since it's got so many good things going for it, and even less so when Sun even document the 'safe rather than sorry' approach.

What Swing Utilities does is to enque a request (in the form of a object, since Java doesn't have anything nice like code blocks) into the single 'Event Queue' thread.So, basically, if you're using a multi-threaded system, you're safe if you use this queue.Of course, if you want to limit yourself to a few tens of updates per second, you can use this approach.But for heavy systems, where timely updates of data is critical, then pretty much ignore everything you've read about Swing threading before.Optimisation tricks: It's a shame that multi-threaded access is one of the less well understood parts of Java, since it's got so many good things going for it, and even less so when Sun even document the 'safe rather than sorry' approach.That happens not because those architectures are not optimized, on the contrary — they are highly optimized, but with a in mind.