Hi,
I just gave up on the roll-my-own GUI and converted to Swing - its what I know and its beautiful. I use direct rendering in my game loop thread and while I know that painting Swing/AWT components directly from such a thread is not safe, I read in a book somewhere that you can stop the AWT Event dispatching thread from painting by installing a ‘NullRepaintManager’, a class you make as a sub-class of RepaintManager that over-rides:
public void addInvalidComponent(JComponent c)
public void markComponentDirty(JComponent c)
public void addDirtyRegion(JComponent c)
public void paintDirtyRegions()
with empty method bodies. You install it as follows::
RepaintManager rm = new NullRepaintManager();
rm.setDoubleBufferingEnabled(false);
RepaintManager.setCurrentManager(rm);
Apparently that stops ‘OS-level’ paint requests but I’m not sure if it stops internal painting on the AWT Event thread. I did this to stop the AWT Event dispactching thread from painting so I can call aSwingComponent.paint(myGraphics) from my game thread without threading problems. It seemed to work fine at first, but sometimes my game freezes and I fear that its because there is a thread conflict. I assume its because things like JTextFields paint themselves (like the flashing caret) on some thread (the Event Dispatching thread?) which conflicts with the painting of that JTextField in my game loop thread.
How can I stop painting in the Event Dispatching thread for good or am I barking up the wrong tree?
Thanks,
Keith