Swing Frame Rate / Custom RepaintManager

Hi,

I am writing a visual 2d equipment simulator using jdk1.3.1 under windows 2000.

I use Swing and AWT as renderer because I take advantage of the Design Time builder (bean box) to allow a fast and easy construction of simulations.

The simulations are mainly composed of reusable objects. The base class for all objects is a custom panel (JPanel) on which Images can be drawn.

Here are my questions :

  1. When there are a lot of animation on screen (lets say many led objects that flashes), the memory usage of the simulation grows very fast.
    I have pin pointed the problem with a Profiler (OptimizeIT) and I have discovered that the paintChildren() method of JComponent creates a lot of RECTANGLE objects to calculate the cliping area.
    Is there a way to control that ?

  2. I have tried to create my own RepaintManager by subclassing the RepaintManager class. I have managed to catch all repaint() calls in the application, and force a repaint on the main application frame every 50ms using a timer, to simulate a fix frame rate. This seems to have free some of the CPU because the EventDispatcher is not longer flooded with repaint() request from all the objects. Is there anything else we can do with a Custom RepaintManager ?

  3. One of the main item I have also discovered is that I am drawing all my components in a panel where cousins (siblings) components can lie on different layer on the same panel (i.e. components are added using the .add(c, 3) where 3 is a layer in JPanel).
    This has a huge effect on performance since the JPanel Swing OptimizedDrawing feature (isOptimizedDrawing flag) must be set to false for the siblings components to be painted correctly. The result is that each time Swing wants to repaint a component, it must calculate the clipping area from the bottom of the hierarchy (frame) to the top (leaf component).
    Is there a way to optimize the drawing without forcing swing to redraw the entire object tree ?

Any comments would be appreciated,

Thanks,

Philippe