2

I have an application that displays plots using JFreeChart. As it happens, these plots are big and JFreeChart is not terribly fast, resulting in atrocious redraw times, particularly when resizing the plot.

What I am after is a way to stretch an image representing the plot while resizing (a bit like the iPhone will present a screenshot of a stopped application while it gets started again), and perform a full redraw only after the user has released the mouse (i.e. once the final size of the plot is known).

The interaction features of the chart sould stay intact (when not resizing, obviously).

Is there a generic solution / Swing wrapper for this? (there is no reason why it should be JFreeChart-specific).

Cheers

Rom1
  • 3,167
  • 2
  • 22
  • 39
  • hmm .. dont quite understand how that would help overly much: at the end of the resize the user has to wait for the "atrocious redraw times" anyway. What difference do you expect/experience during the resize? Also, users might be confused if they try to resize for better fitting the "viewport" but it doesn't change. – kleopatra Sep 08 '11 at 09:06
  • It would help by allowing the user to resize the window in one fluid gesture (no breaks due to the repaint) even though they will have to wait at the end (i.e. it will collapse multiple slow repaints into one). – Rom1 Sep 08 '11 at 09:09
  • you mean, the slow redraw _prevents_ the resizing? If so, sounds fishy to me – kleopatra Sep 08 '11 at 09:20
  • Yes, it is the case; why is that fishy to you? (AFAIK, the redraw happens on the EDT) – Rom1 Sep 08 '11 at 09:35
  • ahh .. okay, so it's actually blocking the EDT, thus preventing every interaction – kleopatra Sep 08 '11 at 09:42
  • yup. if you happen to have links to resources as to what is permitted outside the EDT (for instance offscreen drawing), that would be really cool – Rom1 Sep 08 '11 at 10:34
  • Don't take shortcuts! The list of thread-safe Swing methods gets shorter with each new version; more [here](http://stackoverflow.com/questions/7156949/main-thread-vs-ui-thread-in-java/7158505). – trashgod Sep 08 '11 at 15:55
  • Can you provide an [sscce](http://sscce.org/) that exhibits the problem? Is this a large data set or a slow renderer? – trashgod Sep 11 '11 at 04:22

1 Answers1

3

No concrete answer, just a possible strategy

  • on starting the resize, paint the plot into a BufferedImage and show and resize that image instead of the plot
  • on stopping resize remove the image and show the plot again

in JDK 7, you can use a JLayer for the image/manipulation.

Edit

Alternatively (for JLayer), you could use a CardLayout: showing one card with the image while resizing and the another card with the plot while not resizing. SwingX ImagePainter can do the image scaling during the resize

kleopatra
  • 51,061
  • 28
  • 99
  • 211