Temporarily disable double buffering in Java graphics applet
is there an easy way to disable double buffering in a java applet if necessary? I have a java applet that displays and animates a musical score so I needed it double buffered. However for teaching purposes I need to print this applet. The problem is that before I added buffering the output to the printer was vector based so I could make it as big as I wanted and it would look smooth (and also use the cheaper type of black ink!) but with the double buffering the output is of course an image, and a fairly low res one at that!
开发者_开发百科Basically I need the same applet to use double buffering when it is called with the "display_tune" parameter but to draw straight to graphics with vector output when it's called with the "view_tune" parameter.
Any help much appreciated.
You could try by doing something like
yourComponent.setDoubleBuffered(false);
// your print code
yourComponent.setDoubleBuffered(true);
the method is declared in JComponent
. I used this solution to export a PNG from a Jung graph and it worked. I'm not sure if Jung overrides that method inside their components to a different thing but there's not hurt in trying..
You should globally disable double buffering, not just for one component. Swing has something called a RepaintManager. It allows you to enable and disable double buffering.
精彩评论