Why swing so slow?

I using swing as my game gui with my own look and feel, then I paint swing components to screen directly in every cycle, as below

void gameLoop() {
while(isRunning) {
updateInput();
updateLogic();
renderGameMap();
uiPanel.paint(bufferGraphics);
}
}

And uiPanel.paint(bufferGraphics) drop my fps from 60 to 30? Is there anything wrong? thx

There is a lot of code in Swing. It is slow in regular applications, so don’t use it the way you do. What you need to do is create your Swing GUI around your custom area so that you only update the custom area yourself every game loop. You then let Swing update itself in the usual way.

Take a look at BufferStrategy.

Cas :slight_smile:

Thanks for answering!
CaptainJester, That’s a good idea, but how can I create Swing GUI around custom area and then let Swing update itself in the usual way? If you can give me some example code? thx

http://www.noblemaster.com/public/
Look at “2. Isometric Tile Engine with Heightmap (Java)”. It’s not quite up-to-date but should give you the idea…