fullscreen doublebuffering and swing

I am wondering about the best way to do a fullscreen doublebuffered application that also uses Swing components. In other words, I want to actively manage drawing, but also have the luxury of not writing my own UI code for buttons, listboxes, etc.

The way I’ve done it so far is to create a Frame with a page flipping buffer strategy, to use setIgnoreRepaint on the frame, add components to it, then explicitly render those components in my render loop along with all my other sprites. I transform the graphics context to the appropriate locations for each component and call paint on the component using my buffer strategy’s graphics context.

It seems to work, but I have doubts. I’ve only tried it using JButtons and haven’t bothered yet with other component types.

Is this a bad idea? Am I spawning new threads by creating and adding these components to my Frame that could come back to haunt me? Is there a better way?

I tried setting up a standard fullscreen Swing application and adding a Canvas to my Frame as one of the components (along with buttons, etc). Then I tried creating a bufferstrategy on just the canvas. This works in windowed mode, but in fullscreen only the Swing components show up. The canvas is blank white and won’t draw anything. I can create a single buffer strategy on the canvas and it works, but of course that looks horrible.

As a follow up, I’ve tried this with JButtons and JLists and it does work, if…

I’ve found I need to extend the button and list classes and override the paint method in each of them because, although setIgnoreRepaint does cause them to not be drawn unless I call paint explicitly, they are still painted by an AWT Thread when you click on them to change their state. This causes artifacts. Overriding paint so it does nothing, then adding my own custom paint method that calls the superclass paint appears to fix it.

Geesh. I just think this seems wrong. So there are now still some calls being made to paint() that are doing nothing, thanks to my meddling. Seems like a waste. Is there a way to totally disable any painting so it’s only drawn when I say so? Am I hacking up a big mess or what?

The question is pretty simple: we’re making an Open Press article over of it (look at www.zerosoft.info):

You need to override the basic RepaintManager, and set it as default. You have to override every method that will handle invalid components and dirty regions and leave them blank.

Then you should instantiate it and call the method to disable double buffering ( setDoubleBufferingEnabled(false) ) for Swing, and finally register the new RepaintManager you instantiated with the static method setCurrentManager().

Now you can perfectly use Swing in a active rendering loop, given you’ll will call paintComponents for your main frame.

In the article will be also some hints and tips to display dialog boxes and draggable and resizable windows in fullscreen exclusive mode.

I ve just the same problem. I need to put a JTable on a Canvas which uses BufferStrategy to update all components on it. I add a JPanel with inside a JTable on it and it is ok, but if I try to scroll the JTable it doesn’t work! Any ideas?
Thanks in advance
Ray

I believe that someone has used JButton , JTable or other swing components with BufferStrategy+IgnoreRepaint etc etc. or I MUST rewrite every event about mouse pressed or released for JButton or simulate scrolling table?

Any suggest is appreciated!
Ray