BufferStrategy vs DIY Double Buffering in JFrame

So far, I have done double buffering using create and image, drawing what I wanted for this image using the graphic object associated with it, then drawing this image on the screen using the drawing method. I recently learned about the BufferStrategy class and its use. I was wondering what the pros and cons of the two methods are.

EDIT: I don't think I posed my question very clearly. I wanted to know the pros and cons of both the DIY method and BufferStrategy, and when, if ever, I should use one or the other.

0
source share
2 answers

I've always had good results using the default BufferStrategy for fear

  • Always Build GUI Components on EDT
  • Never draw a thread other than EDT

This great example should double the buffer because it draws the original stream continuously, not EDT . In contrast, this rather busy example relies only on repaint() called in response to Swing Timer . I rarely need an off-screen buffer, except for composite . Finally, this tutorial article offers more recommendations.

+7
source

I recommend reading Painting in AWT and Swing if you haven’t.

I don’t think you usually need Do-It-Yourself double buffering if you use JFrame. Swing has built-in double buffering, which is enabled by default. Manually doing it yourself will simply slow down the job. You can check if double buffering is enabled by calling isDoubleBufferingEnabled () on any of your JComponents.

There are times when you can do it yourself, but this should be the exception rather than the rule. Maybe you are doing something like writing a game, and in this case, perhaps my advice is not applicable. In any case, I hope this is useful information.

+1
source

All Articles