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.
See the related question, Why doesn’t Java support unsigned ints?.
You can work around the limitation by displaying your graphs in a
JListorJTable. TheJList/JTablewill only render the cells that are currently visible. Ideally, you should store the values for your graphs in aListModelorTableModel, respectively, and implement the corresponding customListCellRendererorTableCellRenderer.If you just want a proof-of-concept first, you can shove the Graph
Components directly into aDefaultListModelorDefaultTableModel, and use a renderer whoseget*CellRendererComponent(...)method returns the Graph.