开发者

separate repaints in awt

开发者 https://www.devze.com 2023-03-12 11:03 出处:网络
The \"Painting in AWT and Swing\" docs state the following. \"If multiple calls to repaint() occur on a component before the initial repaint request is processed, the multiple requests may be collaps

The "Painting in AWT and Swing" docs state the following.

"If multiple calls to repaint() occur on a component before the initial repaint request is processed, the multiple requests may be collapsed into a single call to update()."

Is it possible to change this behavior in a component so that multiple calls to repaint never get collapsed into a single call?

开发者_C百科

EDIT: The docs further state this, "The algorithm for determining when multiple requests should be collapsed is implementation-dependent."

My problem is I'm on a mobile platform that does separate calls to repaint and I'm trying to replicate the behavior on the desktop.


I'm guessing you have some long running task that is looping an not updating the GUI as you expect it to. This would be because you are blocking the Event Dispatch Thread so Swing can't repaint itself.

Read the section from the Swing tutorial on Concurrency in Swing. Use the SwingWorker for the long running task to you don't block the EDT and then you can publish results and required and they will be painted as expected.

Or if you problem is with animation, then use a Swing Timer. The tutorial also has a section on timers.


I fear the paint algorithm is pretty hardcoded in swing/awt and they only offer different hooks for different purposes. You can use use this method in swing which would offer what you want, but sadly there doesn't seem to be an awt equivalent. You could try mixing awt/swing, but that's usually not recommended and may lead to strange behavior in some cases as I hear

PS: And for people asking WHY you'd want this: Some apps (mostly games) need synchronous redraws to ensure that their visual appearance keeps up with the internal state - afaik the JScrollbar also uses it internally for example (I haven't looked at the code in question, so take this with a grain of salt - I do understand though why it could be useful in that particular case)

0

精彩评论

暂无评论...
验证码 换一张
取 消