Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] Double Buffering

Started by Kertap Mar 30, 2004 at 4:55 AM 3 replies 950+ views
Original Post
Kertap
Kertap
I was just makeing a form the other night when I noticed that the default constructor for JPanel makes one with a double buffer and a flow layout. Question 1: Does the window the JPanel appear have to be double buffered? Question 2: Is it possible to get access to the JPanel''s buffers or do you call paint()?
GO TO MY WEBSITE.GO NOW.Oh wait I''m not Jesse Custer. Real Life Sux.
cyrax256
cyrax256
Hi!:

1) All the Swing components are double buffered by default, if that's what you ask. The window that holds it doesn't have anything to do with the JPanel.

2) You should override the paintComponent() method (instead of the traditional paint() method). That's because Swing does some things in paint(), and if you override them the result wouldn't be the best.

Bye,

Ciro.

[EDIT: I said update() method, which was wrong. Thanks to Anonymous Poster]

[edited by - cyrax256 on March 30, 2004 1:00:58 PM]
Strife
Strife
Just FYI, this is one of the questions that will be appearing in the FAQ in the near future, so stay tuned.
nonnus29
nonnus29
You can use createBufferStrategy(int numofbuffers) to get double buffering in a Window or Canvas class/subclass. Then use getDrawGraphics() to get the Graphics to the current backbuffer. Then do a BufferStategy.show() to flip them.

See the wiki here for an example:

http://community.java.net/games/

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.