I have some java code that I use for animation of zooming in 3 contexts: 1. alt-scroll, 2. a static 150ms animation (a loop with a 10ms sleep) upon button press, and 3. via a click-hold of a button done by a loop in a thread (a loop with a 100ms sleep which continues to zoom as long as the mouse button is held down).
Each mechanism calls the same method for a zoom increment. Inside that method, zooming is managed on each axis independently (i.e. zoom on x and zoom on y).
However, while mechanisms #1 & #2 work great, I'm having trouble with #3. Sometimes the repaints are being done mid-stream, meaning the repaint is sometimes triggered between each of the dimension updates, which causes the animation of the zoom to look jerky.
I've tried a number of variations of different ways to control repainting to varying levels of success.
- Tried setting -Dswing.volatileImageBufferEnabled=false on the command line - did not work at all
- Tried calling paintImmediately in various places - did not work at all
- Tried using a combination of RepaintManager.currentManager(c).markCompletelyClean(c) and RepaintManager.currentManager(c).markCompletelyDirty(c) - while this was able to prevent repainting, I couldn't figure out how to get it to paint at each zoom increment reliably.
- Tried using setVisible(boolean) - this worked to stop the jerky repaints between updates in each dimension, but caused the panel to "flash" on every repaint
Perhaps I just haven't figured out the proper order to call things in. Does anyone know how I can manage this? I suspect the reason why this is happening is because the updates are being generated from a thread whereas the other mechanisms are happening serially, but I know of no other way to detect a click-hold event on a button press using swing.