Jitter/performance problem with sibling sketcher component

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Jitter/performance problem with sibling sketcher component

blainebell
Here is an example of a "sketcher" component as a sibling of a JoGL window:

JitterProblemJoGL.java

When you move the mouse quickly on the sketcher, the rendering slows way down (depending on your hardware, if its fast, you might need a lot of scribbles before it starts slowing down).  If you change the "show_problem" variable defined at the top of the class to false, then its fixed.  Is this expected behavior?  Why does the repainting of the GLCanvas fire a refresh of the sibling component?  Is there a workaround for this?

Another (much smaller) issue is shown when the "use_panel_above_canvas" variable is set to true, the canvas does not get shown.

Thanks!

Blaine
Reply | Threaded
Open this post in threaded view
|

Re: Jitter/performance problem with sibling sketcher component

Wade Walker
Administrator
My guess (from only a quick look at the code, so I could be wrong) is that you're flooding the Sketcher with paint events. If the Swing event queue gets too full, responsiveness will go down until you stop moving the mouse and let it clear the events out.

Swing is supposedly able to combine repaints that happen before the paint method is actually called, but in your case you're repainting the Sketcher on every mouse move (from within the Swing event dispatch thread), and also on every timer tick (from a separate timer thread). Repainting the Sketcher on mousemove should be all that's required.

For the sibling repainting issue, you might look at isOptimizedDrawingEnabled at http://java.sun.com/products/jfc/tsc/articles/painting/. Normally siblings shouldn't cause repaints on each other unless they overlap, but if a sibling is doing something weird like calling repaint on its parent, you could see this behavior.