Details
-
Type: Bug
-
Status: Open
-
Priority: Trivial
-
Resolution: Unresolved
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: awt-gui
-
Labels:None
Description
Progress bar (and likely other animations too) are stuttering unless a cursor is being moved over the window.
The cause is that some windowing systems do not sync the window state to the screen when they feel like it's not necessary. Check out `Toolkit.sync()`
Here is the code I wrote in the past to do animation (with all the unnecessary stuff stripped off):
~~~
window.createBufferStrategy(2); // JFrame instance
BufferStrategy bs = window.getBufferStrategy();
while (true) {
update(timeDelta); // update animation
Graphics g = bs.getDrawGraphics();
window.paintComponents(g); // paint animation
g.dispose();
bs.show();
window.getToolkit().sync();
// sleep
}
~~~
The cause is that some windowing systems do not sync the window state to the screen when they feel like it's not necessary. Check out `Toolkit.sync()`
Here is the code I wrote in the past to do animation (with all the unnecessary stuff stripped off):
~~~
window.createBufferStrategy(2); // JFrame instance
BufferStrategy bs = window.getBufferStrategy();
while (true) {
update(timeDelta); // update animation
Graphics g = bs.getDrawGraphics();
window.paintComponents(g); // paint animation
g.dispose();
bs.show();
window.getToolkit().sync();
// sleep
}
~~~