Java Component Maximum Size

Go To StackoverFlow.com

1

I've run into an rather irritating problem in java. I have a program that runs a bunch of simulations in java, there is a lot of data generated and it's all displayed on "graph" objects. I created a component called "Graphs" that displays a long list of these "graph" objects using a GroupLayout and placed it inside a Jscrollpane.

The problem i'm having is the end half of "Graphs" is being cut off. The maximum size that the component can get to is 32,767 Which happens to be the same as 2^15 − 1 (maximum size of a signed 16 bit number). It would seem that component size is being stored as a 16 bit signed number and not a 32 bit integer as I first thought.

The question I have is thus.

Is there any way of changing the way java stores the size of components, and therefore create components larger than this size?

If not what would the best way to tackle this problem? I would like to show all this info on one panel. Even if I were to "stack" "Graphs" components on top of each other, the parent component would still end up outside of the maximum size.

Thanks in advance.

Chris.

2012-04-03 21:48
by Chris192
It might be a long shot, but could you sub-class the Graph class and modify your member datatypes to be larger (BigInteger)? My apologies if that's not an option - collinjsimpson 2012-04-03 22:11


2

See the related question, Why doesn't Java support unsigned ints?.

You can work around the limitation by displaying your graphs in a JList or JTable. The JList/JTable will only render the cells that are currently visible. Ideally, you should store the values for your graphs in a ListModel or TableModel, respectively, and implement the corresponding custom ListCellRenderer or TableCellRenderer.

If you just want a proof-of-concept first, you can shove the Graph Components directly into a DefaultListModel or DefaultTableModel, and use a renderer whose get*CellRendererComponent(...) method returns the Graph.

2012-04-03 22:09
by rob
I'm not sure how this would fix the problem, as even if everything was in a JList, which only rendered what was on the screen. The list would still have to be a large size and placed inside a ScrollPane - Chris192 2012-04-03 22:33
It seems like you're assuming the JList/JTable lays out all of the cells in a huge panel, then uses a viewport to display just part of the huge panel. Fortunately, that's not the case. For items m..n which would be visible in the viewport, the JList uses a single instance of the renderer to "stamp" or paint those items. After rereading the other answer, I think Martijn is suggesting that you do something similar, only without using the built-in APIs that abstract out the ugly details - rob 2012-04-03 23:16
Fixed my problem, thanks a lot - Chris192 2012-04-04 15:33
Glad I could help - rob 2012-04-04 18:12


1

I know this approach might be a bit harder to accomplish but it will work a better than your currrent approach. Try to add a scrollbar next to your Graph, not a scrollpane. Update the content of your Graph dynamically, according to the position of the scrollbar, by adding a listener to the scrollbar.

2012-04-03 22:01
by Martijn Courteaux
It's not just one graph. It's a long list of graphs. :S but that approach might work :P - Chris192 2012-04-03 22:02
Why would that make a difference - Martijn Courteaux 2012-04-03 22:05
It wouldn't, Fair point - Chris192 2012-04-03 22:29