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