> > However, my question is: is it OK, from within an event handler, to
> > paint using getGraphics() PURELY AS AN OPTIMIZATION, AS LONG AS
[quoted text clipped - 5 lines]
> handle some cross-hair cursor, selection or some interactive resizing),
> have a look at paintImmediately().
I didn't realize that paintImmediately() can be called with a
rectangle. I've since tried that, and performance is surprisingly
good. Swing does a really nice job of optimizing painting, even within
a single component.
So now I'm sold on paintImmediately(), but I still would like to
suppress the double buffering overhead, if possible. Double buffering
causes the entire screen image to be copied into the offscreen image
buffer, and for something as interactive as this I'd like to do as
little redrawing as possible.
Can I de-activate double buffering temporarily while calling
paintImmediately(), then re-activate it after I'm done?
> If you would have added just another shape, etc. to the drawing,
> consider just calling repaint() with the affected region as parameter.
> Especially if you have no need for immediate feedback.
Yes, there is a need for immediate feedback. It's a rectangular region
selector, so each mouse movement event requires a repaint of the
selection rectangle.
> In both cases consider to make sure that you observe the cliping area
> inside paintComponent(), so you don't paint more than necessary.
[quoted text clipped - 4 lines]
> don't have many things to paint, you can leave the entire cliping to
> Swing, it isn't too bad at it.
These are all great tips. Thank you for your time.
> /Thomas
Mike Carrato
ak - 16 Feb 2004 16:15 GMT
> Can I de-activate double buffering temporarily while calling
> paintImmediately(), then re-activate it after I'm done?
JComponent#setDoubleBuffered(true);
--
____________
http://reader.imagero.com the best java image reader.
Michael Carrato - 17 Feb 2004 15:35 GMT
> > Can I de-activate double buffering temporarily while calling
> > paintImmediately(), then re-activate it after I'm done?
> >
> JComponent#setDoubleBuffered(true);
Yes, but:
(1) Can I switch just before paintImmediately() and switch back just
after?
(2) Do I call setDoubleBuffered? on the JComponent itself, or do I
need to call it on the enclosing frame?
Mike
Thomas Weidenfeller - 17 Feb 2004 15:55 GMT
> Yes, but:
> (1) Can I switch just before paintImmediately() and switch back just
> after?
> (2) Do I call setDoubleBuffered? on the JComponent itself, or do I
> need to call it on the enclosing frame?
http://java.sun.com/products/jfc/tsc/articles/painting/index.html#db
and
http://java.sun.com/products/jfc/tsc/articles/painting/index.html#paint_process
should get you started.
/Thomas
Michael Carrato - 17 Feb 2004 21:21 GMT
> > Yes, but:
> > (1) Can I switch just before paintImmediately() and switch back just
[quoted text clipped - 11 lines]
>
> /Thomas
Thanks for the links. I had read this article a few days ago, but I
was still stuck on the getGraphics()-based solution, so I forgot about
it.
So, based on everything I've read, I am planning to try the following
in my event handler:
boolean isDB =
theJComponent.getRootPane().isDoubleBuffered();
//turn off double buffering, temporarily
theJComponent.getRootPane().setDoubleBuffered(false);
paintImmediately(...);
//restore the original buffering setting.
theJComponent.getRootPane().setDoubleBuffered(isDB);
Thanks again for your help.
Mike Carrato