II’m working on a basic JFrame extension that uses active rendering via BufferStrategy. I have overridden the RepaintManager with a null version and setIgnoreRepaint(true) for all Swing components. Rather than painting directly on the JFrame, I want to paint onto a JPanel that I am placing inside the frame, so that I can take advantage of the LayoutManagers. I’ve got the basic framework up and running, but the performance seems awful. I’ve placed a JPanel inside the frame, and a JLabel inside the panel that I am displaying the fps on. When the window is maximized (1280x1024), the fastest framerate I get is around 140. This seems ridiculous for such a simple setup, since I can play Quake3 at over 200fps on this machine (yes, I know Q3 uses OpenGL, but still…).
The two factors that seem to change performance the most are…
-
The number of buffers in the BufferStrategy. Basicly, the more buffers I use, the slower the framerate. double buffering gives 140fps, while single buffering gives 170fps. Triple buffering runs at 105fps.
-
Use of getLayeredPane().paintComponents(g) vs paintComponents(g). Using the layeredPane’s paintComponent method is about 30fps faster than using the JFrame paintComponent method, but it causes the layout to be shifted up and to the left, which defeats the entire purpose of the layout managers.
Any suggestions would be greatly appreciated.