Skip to main content

draw on big panel

1 reply [Last post]
jankod
Offline
Joined: 2005-09-18

I'm working on one graphical editor using java2d.
My JPanel is very wide (up to 8 million pixles) and is located in JScrollPanel.

I would like to know is there a way to draw it and not to be too slow?

There is option to draw background in BufferedImage and at every display draw from that image on panel with all changes made in editor by user. The problem is that the image is too big to be kept in the memory.
Second option is to draw only that what is currently showed in the panel but then it must calculate which part is seen and what to draw.

Is there any other way/trick?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
bchristi
Offline
Joined: 2005-11-15

> Second option is to draw only that what is currently
> showed in the panel but then it must calculate which
> part is seen and what to draw.
>
> Is there any other way/trick?

This is a common pattern in applications which use very large JTables whose data models are too large to fit in memory. It should also be applicable to a very large graphic.

If generating the graphic is very compute-intensive, perhaps a hybrid approach would work well - calculate the visible portion of the image as well as a couple screen's worth in either direction. This would improve scrolling performance while still saving quite a bit of memory.

There could well be people who have experience with such techniques on the Java2D and/or Swing forums, if you want to inquire there.