Skip to main content

Flicker problem during zooming action

5 replies [Last post]
Noah_1234
Offline
Joined: 2006-02-14
Points: 0

Hello fellow Java gurus,

I've been working on a project and reusing graphics code from a third party for a particular GUI that I'm currently building. The code that I am reusing is a graphing tool called PtPlot which is part of the Ptolemy package found at this link: http://ptolemy.eecs.berkeley.edu/java/ptplot/

My application is very dymanic and is intended to have a very busy display, one which will be continuously populated with hundreds of thousands of points and millions worst case. My display is also continually refreshed at a predefined rate and can be zoomed in and out at user's discretion.

PtPlot contains classes such as Plot.java and PlotBox.java and are mainly for static graphic displays. They have their own zoom, pan and other graphing functionalities. A class called PlotLive.java was what interested me. Further study of this class revealed that it wasn't the dynamic graphing tool I was looking for.

My prototype application seemed to work ok. It still needs performance boosting, but the main problem occurs during zooming. You guys obviously know that during a conventional zoom, a rectangle is drawn around the area the mouse was dragged over. Now, using the classes mentioned earlier for static graphical displays the rectangle drawn is perfect, smooth and zoom works well. However, for dynamic displays, because I am refreshing the screen at a fast rate, the zoom rectangle that is drawn is repeatedly being refreshed as well, causing a flicker effect, and the rectangle no longer looks like a rectangle. The zoom function works regardless though, but I don't want the customer to zoom in and not be able to see a clear rectangular zoom area.

So basically the problem occurs because the screen in continuously being refreshed. I'm not sure how to fix this because the code I'm reusing is so complex and so suited to static displays. Any ideas anyone?

Also, do any of you know whether my problem could be solved by taking advantage of hardware accelerators? I'm still new on the subject of such things by the way. Thankyou. Any feedback is much appreciated.

Kind regards,

Noah.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
loubs001
Offline
Joined: 2006-01-05
Points: 0

Maybe make sure your component is double buffered (setDoubleBuffered(true)) though JPanels are double buffered by default (JComponents arent though).

If that doesnt work, try putting a transparent component over the top (perhaps with JFrame.setGlassPane) and draw your rectangle on that.

Noah_1234
Offline
Joined: 2006-02-14
Points: 0

Thanks for the response loubs. I have contemplated about using a transparent panel or frame over the actual main graph plotting but I didn't pursue it because it seemed like a bit of a workaround rather than a proper solution, if you know what I mean.

Is that how most applications would perform the zoom technique, that is, to have a transparent pane on which to draw?

Also, are there any more suggestions?

jammerie
Offline
Joined: 2005-11-14
Points: 0

I recently had to work on a GUI that could potentially display thousands of objects on the screen. So I ran into some rendering problem such as yours. What I could think is perhaps if you can alter the system to render your zoom rectangle last, it might still cause a flicker, but at least it'll still provide the user some means to zoom in / zoom out.

Just my 2 cents worth.

Noah_1234
Offline
Joined: 2006-02-14
Points: 0

Thankyou jammerie for your response. Just want to let you know that the zoom in and zoom out functionality work fine. The only problem is the flickering that occurs. I can tell the customer that the zooming works except I don't think they will believe me once they see the flicker for themselves, and this is what I want to avoid.

By the way, could you please explain why rendering the zoom rectangle last would help in any way? I don't understand what this will achieve. Thankyou very much.

Kind regards,

Noah.

Noah_1234
Offline
Joined: 2006-02-14
Points: 0

Basically, my question is, what is the best way to refresh the screen without making the zoom rectangle flicker while being drawn?

Because at the moment, the rectangle being drawn is not complete, that is, it only shows two sides, that is the bottom side and the right side of the rectangle as I select the area to zoom into (btw, I'm zooming from top-left corner to bottom-right corner). The refreshing just does not allow for the rectangle to be drawn completely. Thanks again.