Archived

This topic is now archived and is closed to further replies.

Kertap

[java] Double Buffering

Recommended Posts

Kertap    122
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()?

Share this post


Link to post
Share on other sites
cyrax256    149
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]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
That should be override paintComponent(), look at the java tutorial for doing custom 2D graphics.

Share this post


Link to post
Share on other sites
nonnus29    105
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/

Share this post


Link to post
Share on other sites