*
The moose likes Java in General and the fly likes OutOfMemory Exception and JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "OutOfMemory Exception and JTable" Watch "OutOfMemory Exception and JTable" New topic
Author

OutOfMemory Exception and JTable

Tim Jones
Greenhorn

Joined: Apr 06, 2008
Posts: 28
Hi

I have 2 Object[][] with about 700-1000 values in one or or both. When these arrays are added to the JTable. an OutOfMemory Exception occures on line 18. After increasing the Heap Size and running the app, a warning message pops up indicating RAM is running low and shortly after the OS hangs. Why is this happening?

I'd like to display these values in a table like format, some advice will be appreciated


I assuming this is a Memory Size Problem (Memory leak?)

Thanks


Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

You're creating a 1000 x 1000 array but only using 4 of the 1000 columns. Were you going to add code to use the rest later? Because a table with 1000 columns isn't really a good candidate for a JTable.
Tim Jones
Greenhorn

Joined: Apr 06, 2008
Posts: 28
Paul Clapham wrote:You're creating a 1000 x 1000 array but only using 4 of the 1000 columns. Were you going to add code to use the rest later? Because a table with 1000 columns isn't really a good candidate for a JTable.


Yes, the rest of the columns will be populated in later. If JTable is not the best option in this case, what is the alternative?

Thanks
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

So that wasn't a mistake? You really do plan to have a square table? Your existing code looks like you plan to have 1000 rows but only 4 (or maybe 7) columns.
Tim Jones
Greenhorn

Joined: Apr 06, 2008
Posts: 28
Paul Clapham wrote:So that wasn't a mistake? You really do plan to have a square table? Your existing code looks like you plan to have 1000 rows but only 4 (or maybe 7) columns.


Answer to all these questions is a Yes.

just so it is clear, there are 7 columns in total with give or take 1000+ rows (values).

Anyone have any suggestions?

Thanks
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

a table with 1000 rows in is a pretty bad UI (in my opnion). I would stick a filter on it, so the user can actually see data that is relevant to them.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

1000 rows is nothing for several applications, including but not limited to database editing / browsing applications.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Tim Jones
Greenhorn

Joined: Apr 06, 2008
Posts: 28
Rob Spoor wrote:1000 rows is nothing for several applications, including but not limited to database editing / browsing applications.


And your point is?

Tim Jones
Greenhorn

Joined: Apr 06, 2008
Posts: 28
Wendy Gibbons wrote:a table with 1000 rows in is a pretty bad UI (in my opnion). I would stick a filter on it, so the user can actually see data that is relevant to them.


Not sure how that will be possible inside a JTable (DefaultTableModel will only take Object[][)]?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

Tim Jones wrote:
Rob Spoor wrote:1000 rows is nothing for several applications, including but not limited to database editing / browsing applications.


And your point is?


It was a response to Wendy's opinion that 1000 rows is too many, nothing else.

Tim Jones wrote:
Wendy Gibbons wrote:a table with 1000 rows in is a pretty bad UI (in my opnion). I would stick a filter on it, so the user can actually see data that is relevant to them.


Not sure how that will be possible inside a JTable (DefaultTableModel will only take Object[][)]?

Perhaps you can create your own AbstractTableModel subclass that does not copy data, but instead uses the original data source with its getRowCount, getValueAt and setValueAt methods.
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3606
    
  60

Rob Spoor wrote:
Perhaps you can create your own AbstractTableModel subclass that does not copy data, but instead uses the original data source with its getRowCount, getValueAt and setValueAt methods.

I second to that. I have a table model capable of displaying millions of cells (if some unfortunate user opens the form in that way), because I don't have a physical object for every cell in the table.

I managed to create a table with around 100.000 columns and 10.000 rows just for testing. It works well, only the horizontal scrolling gets a bit slower when scrolling too far to the right - JTable apparently does not cache horizontal position of the columns and it takes some time to compute them while drawing individual cells. (Or maybe I did it to me myself - I've a customized header renderer in there.)

Note: not that the users usually use these insanely large tables. But whichever limit we impose, they always want a few rows more. The user interface allows them to export the contents of the table to MS Excel, which can accommodate million rows and thousand columns nowadays....
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Tim Jones wrote:just so it is clear, there are 7 columns in total with give or take 1000+ rows (values).


Thanks for the clarification. So my suggestion would be to change your array declaration

so that it only has 7 columns instead of give or take 1000 columns.
Tim Jones
Greenhorn

Joined: Apr 06, 2008
Posts: 28
Paul Clapham wrote:
Tim Jones wrote:just so it is clear, there are 7 columns in total with give or take 1000+ rows (values).


Thanks for the clarification. So my suggestion would be to change your array declaration

so that it only has 7 columns instead of give or take 1000 columns.


After editing the column size as suggested, the initial problem has gone away. It was the column size all long. I think for added measure I'm going to go ahead and switch to Abstract Table Model just in case.

Thanks
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

I stand by my comment, what is any user going to do with 1000 rows of data? all they are going to be doing is searching for the rows which are actually relevant to them, or trying to work out summaries.
it may be physically possible with a new table model, but i would be willing to bet it will still run like a dog.

for a technical answer: The data is filtered before the table is created.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Wendy Gibbons wrote:I stand by my comment, what is any user going to do with 1000 rows of data? all they are going to be doing is searching for the rows which are actually relevant to them, or trying to work out summaries.
it may be physically possible with a new table model, but i would be willing to bet it will still run like a dog.


Here's an example: I have an application which I run very frequently, and its background data consists of trees with about 10,000 nodes each. I'm not running the app because I want to search for particular nodes, they are all potentially relevant. I would never ask the writer of the app (which is also me) to reduce the amount of data I get.

And as for running like a dog... it was starting to get slow when I have about twenty of these trees loaded in memory, but then I upped the available memory to 1 gigabyte and now it's fine.

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: OutOfMemory Exception and JTable
 
Similar Threads
OutOfMemory error
jtable
OutOfMemory with 2000 records.
JTable and Custom Columns
jtable not displayed