Posted by kilosi
on August 6, 2009 at 4:39 PM PDT
I am looking for some advice on an issue I am having.
I have a program that draws a large image on the screen as a JLabel. On this JLabel, you can place down item that will play an animation (for example, they'll blink RED-YELLOW-GREEN). I have overloaded the paintComponent method to handle drawing the placed items. This JLabel placed on a JDesktop. Then I have several JInternalFrames open that can be moved around on top of this JLabel. These JInternalFrames are used to display various information about the items that have previously been placed.
I have a RepaintThread that will repaint the Image (by calling the repaint() method) every 100 MS. However, this causes a serious performance degradation. What ends up happening is that all the JInternalFrames are redrawn. 99% of the time, these JInternalFrames do not need to be repainted because their data does not change.
So, I am trying to come up with some solutions to overcome this issue.
One idea I had was to draw an initial image of the screen (user interfaces and the placed items) and save that. Then when an update occurs on the items, I would clip the area and then draw the new area on the saved image. At which point, I would then draw this newly updated image. If the user dragged, closed, or opened a JInternalFrame, I would redraw the initial image and replace it. I hope, that this would bypass the issue I am having with unnecessary updates on the JInternalFrames. So in summary, this method would only update the UI if it was absolutely necessary to do so.
I tried to accomplish this with an initial attempt, but it quickly became apparent it would be much more complex than I had originally intended. (See below if you want to know what I tried).
So I am looking for any advice on this matter. If you need more information please let me know.
I clipped a small area in the JLabel to around 100x100 in the center of the screen. When I ran my program, only the clipped area was being displayed (good). But then I looked at my JInternalFrames and noticed that they were being displayed and were in fact, being updated still. So I would have to find a way to attach them to the current Graphics object in the JLabel, I guess. It was here, that I decided to stop and post here.