How can I create a sparse data model for my table?

John Zukowski

Create a custom table model that maps rows and columns into a Hashtable/HashMap. That way, only those cells with data will take up space/memory.

public class SparseTableModel extends AbstractTableModel {
  Hashtable model = new Hashtable();
  public Object getValueAt(int row, int col) {
    return model.get(new Point(row, col));
  public void setValueAt(Object data, int row, int col) {
    model.put(new Point(row, col), data);