Question

I have written a hex viewer.

However, I found a limitation in Swing. If you have a 3GB file and you're rendering at 20 pixels per row, the total height of the component is:

(3GB / 16 bytes per row) * 20 pixels per row = 3.75GB

At this point, Swing fails to render anything because the value overflows Integer.MAX_VALUE.

This is my best idea so far:

  • Clone enough of Java2D and JComponent to make an alternative to JComponent which does all rendering in long coordinates.
  • Clone JViewport so that you have a way to render the view of the component/
  • Put that alternative JViewport into a JScrollPane like you would normally do.

This seems like a lot of work, but such a component might be useful for things like large diagrams or large text documents.

I considered just paging it, but it seems like it would be awkward when you're using the Find feature and it matches text crossing a page boundary.

The (non-Java) hex viewer I normally use (Hex Fiend) doesn't use paging either. It just scrolls the whole height of the document as if it's not a problem.

Does anyone know a good way to get around this sort of thing?

Was it helpful?

Solution

You don't need to draw your hex viewer in long coordinates because you only need to draw the part of the file that you want to be visible at the moment. JScrollPane is a very useful tool for scrolling around large components, but you don't need it. If you want to scroll through so much stuff that it's troublesome to have a component big enough to hold it all, then you can simply do the scrolling by making a JScrollBar and painting your component according to the position of the scroll bar.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top