Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Active Rendering using Only Swing

Tags:

java

swing

Is it possible to perform active rendering with double buffering using only Swing components (no Canvas or any other AWT components)? This means there should be no reliance on the EDT to handle any aspect of rendering.

EDIT: The program that I am writing that prompted this question is not fullscreen.

like image 214
1000000000 Avatar asked Jul 10 '26 05:07

1000000000


1 Answers

Java supports active rendering in the Full-Screen Exclusive Mode API:
Passive vs. Active Rendering

But also on AWT there are ways to take explicit control over the rendering (without having to go full screen):

  • Have your rendering component extend java.awt.Canvas
  • Ignore repaint requests from the EDT: setIgnoreRepaint(true);
  • Create a buffer strategy for double buffering (page flip)
  • Update your buffer after painting: strategy.show()
  • Bring your updated graphics to the screen: Toolkit.getDefaultToolkit().sync();

Here's a good article on that topic, including an example:
Java Game (Actually the most efficient way to repaint)

like image 144
Peter Walser Avatar answered Jul 14 '26 01:07

Peter Walser