• Post Reply Bookmark Topic Watch Topic
  • New Topic

createBufferStrategy, Double Buffering, and Swing  RSS feed

 
Andy Selador
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you need to create a buffer strategy for Swing components like AWT's Canvas? Is double buffering automatic? How would you do it your own way if it is set to false for Swing components?

For Swing:
If I have a graphic that will white out a JPanel and crate a circle at different places (i.e. animation), do I need to worry about flickering? Should I draw on an offscreen image and have that image drawn on screen (via a call to repaint() and overriding paintComponent())?

For a paint application that was to fill ovals when the mouse is dragged, skipping occurred if the mouse moved to fast. Is there a way to avoid this other than setting the stroke properties and using drawLine()?

Thanks,

Andy
 
Campbell Ritchie
Sheriff
Posts: 53779
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most drawing in Swing is done straight onto a JPanel. If you look at that, you see there is an option to set double buffering in its constructor, which it might be a good idea to try out.

Not sure what the best way to sort your problem out is, but repaint() and overriding paintComponent() (with super.paintComponent(g); as the 1st statement in the method) sounds a good place to start.
Don't know about skipping ovals. Sorry.

Anybody else??
 
Andy Selador
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been thinking about the ovals not being continuous, and I think it is because the event dispatch thread can only deal with a mouse motion event so quickly, and also because if they were absolutely smoothly connected, a ridiculous amount of events would be dispatched.

Thank you for the help with buffering. I think I've been thinking too into how buffering works when I am not really running into too many problems. I think all Swing objects allow for buffering easily, while AWT required the creation of buffering strategies to handle it (and therefore flickering was a problem if you didn't use a Canvas or Window object with a buffering strategy). At least thats my guess.

Andy
 
Campbell Ritchie
Sheriff
Posts: 53779
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're probably correct about separate ovals; last time I tried that sort of application I had the same effect and decided I liked it!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!