custom Scrollable Component?

Hello

The task before me is to scroll a HUGE image, preferably using Swing. The image is going to be on the order of 100 pixels by 60,000 pixels. I don’t want to create an image that big or create a bunch of tiles that add up to it, but rather generate the visible portion of the image on the fly. Basically I want a JTable-like widget that only draws what is visible and scrolls quickly. In fact JTable would be useful if I could actually get cells that were 3 pixels by 3 pixels with absolutely no space between them. [ JTable.setIntercellSpacing( new Dimension( 0, 0 ) ) leads to intercell spacing of 2 pixels. perhaps I’m using that wrong. ]

I’m fairly confident I can do this with a custom Component wired to a JScrollbar through an AdjustmentListener. I had hoped to find examples somewhere that used JScrollPane and a custom widget, but nothing is coming up.

Any thoughts or pointers to examples appreciated.

  • duncan

Generate it on the fly from what?
Where is the data for this image coming from?

Do you hope to stream it from a file? or over a network?
or is it going to be generated at runtime from some algorithm or other?

600001004 is only 22meg or so - whats the problem with loading the entire image in (if its from a file)?

The image is a representation of float data already in memory. In this example, the 22meg image would have been generated via a simple algorithm from 2.4meg (3320,0004) of floats.

600001004 is only 22meg or so - whats the problem with loading the entire image in (if its from a file)?

Perhaps I’m being overly pessimistic. I’ll give this a try with the complete image and standard Swing, and post my results.

ah so the data is already in memory, and you just want to be able to generate different portions of it as required.

You should be able to do that by creating your own implementation of the ImageProducer interface, and use Toolkit.createImage(ImageProducer) to get an Image.

Depends how expensive the generation process is,
as to whether you want to pregenerate the image, or generate it on the fly.

One way to do it:
(1) extend JComponent
(2) override paintComponent(Graphics g) and in this method call g.getClipBounds() to see what needs painting, then paint this region.
(3) set the size of the component to 100 pixels by 60,000 or whatever and put the component in a scroll pane.

Using JScrollPane, ScrollablePicture, and ImageIcon as described here
http://java.sun.com/docs/books/tutorial/uiswing/components/scrollpane.html I was able to display the 22meg image and scroll with good performance.

Unfortunately it took me a very long time to generate the image, so I will be investigating the methods you guys have mentioned for generating only what I need to display.

thanks!