JDK-4140598 : JTable has size limitations
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: solaris_2.6
  • CPU: sparc
  • Submitted: 1998-05-20
  • Updated: 1999-04-14
  • Resolved: 1999-04-14
Description

Name: rk38400			Date: 05/20/98


Create a table with Integer.MAX_VALUE rows (2147483647). Display
it. Only the first 126322567 rows are displayed. Here is a sample
program:

import java.awt.*;
import com.sun.java.swing.*;
import com.sun.java.swing.table.*;

final class Main
    extends JFrame
{

public static void
main(String[] args)
{
    new Main();
}

Main()
{
    getContentPane().setLayout(new BorderLayout());

    AbstractTableModel dataModel =
	new AbstractTableModel() {

	public Class getColumnClass(int columnIndex)
	    {
		return String.class;
	    }

	public int getColumnCount()
	    {
		return 1;
	    }

	public String getColumnName(int columnIndex)
	    {
		return "Row Number";
	    }

	public int getRowCount()
	    {
		return Integer.MAX_VALUE;
	    }

	public Object getValueAt(int rowIndex, int columnIndex)
	    {
		return Integer.toString(rowIndex + 1);
	    }

	public void setValueAt(Object aValue, int rowIndex, int columnIndex)
	    {
	    }

	public boolean isCellEditable(int rowIndex, int columnIndex)
	    {
		return false;
	    }

    };

    // Create the JTable

    System.out.println("Creating table with " +
		       dataModel.getRowCount() + " rows");
    System.out.println();
    JTable table = new JTable(dataModel);

    TableColumnModel columnModel = table.getColumnModel();
    int columnCount = columnModel.getColumnCount();
    for (int i = 0; i < columnCount; i++) {

	TableColumn column = columnModel.getColumn(0);

	column.setHeaderValue("Row Number");
	column.setCellRenderer(new DefaultTableCellRenderer());
	column.setResizable(true);
	column.setMinWidth(200);
    }
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    JScrollPane scrollpane = new JScrollPane(table);
    getContentPane().add(scrollpane);

    // Display the window

    pack();
    setVisible(true);
}

}
(Review ID: 30808)
======================================================================
In addition to this, it is possible to use this same sample program to make the table barf up exceptions.  Here's how:

1. Launch the sample
2. Scroll to row 120 million or so
3. Try to click in a cell

it will throw and OutOfMemeoryError from Bitset.ensureCapcity.  This is called indirectly from DefaultListSelectionModel.changeSelection().
steve.wilson@eng 1998-05-27

Comments
EVALUATION Yup. It displays exactly the number of rows specified by the submitter. In addition there seems to be a large amount of memory required to do selections in large tables. steve.wilson@eng 1998-05-27 It is time to admit that this is not going to be fixed. There is no doubt that there is a limit on the number of rows that it is possible to display on the table, but this is true anyway since the number of rows is specified by an int and therefore is bounded at Intger.MAX_VALUE. So the bug might better by characterized as, the upper bound on the number of avbailible rows in the JTable is 126 million rather than 2 billion. Since tables with more than 126 million rows are unusable anyway (the table will move by more than a page when the scrollbar is moved by a single pixel) this does not seem so bad. The problem, incidentally is almost certainly in the calculation of the table's height which will be doing multiplications of integers that result in the wrapping of the result when it exceeds Integer.MAX_VALUE. The second issue is the selection model which cannot store, even one bit of information for the number of rows in the table without running out of memory. This actually points to the reason for giving up here, if most VMs won't have enough memory for one bit of information per row what useful information could be displayed in such a table? Having said that there are plans to replace the BitSet inside the DefaultListSelectionModel with a sparse implementation which does not have an O(n) cost in the size of the model being represented. philip.milne@eng 1999-04-14 On thinking about this a little more ... All Components have an upper bounds on their height (and width) due to the fact that they use ints to represent their bounds. The maximum height of a table is therefore 2^31 = 2147483647. For a table: TableHeight = (RowHeight + Spacing) * RowCount The maximum number of rows in a table with default rowHeight (16) and InterCell spacing (1) is therefore: 2147483647/17 = 126322567
11-06-2004