FileDocCategorySizeDatePackage
SpreadsheetModel.javaAPI DocExample3153Mon May 01 14:41:56 BST 2000None

SpreadsheetModel

public class SpreadsheetModel extends AbstractTableModel

Fields Summary
Expression[]
data
Constructors Summary
public SpreadsheetModel(int rows, int cols)

    data = new Expression [rows][cols];
  
Methods Summary
public intgetColumnCount()

 return data[0].length; 
public intgetRowCount()

 return data.length; 
public java.lang.ObjectgetValueAt(int row, int col)

    if ( data[row][col] != null )
      try { return data[row][col].eval(  ) + ""; }
      catch ( BadExpression e ) { return "Error"; }
    return "";
  
public booleanisCellEditable(int row, int col)

 return true; 
public static voidmain(java.lang.String[] args)

    JFrame frame = new JFrame("Excelsior!");
    frame.addWindowListener(new WindowAdapter(  ) {
      public void windowClosing(WindowEvent we) { System.exit(0); }
    });
    JTable table = new JTable( new SpreadsheetModel(15, 5) );
    table.setPreferredScrollableViewportSize(
        table.getPreferredSize(  ) );
    table.setCellSelectionEnabled(true);
    frame.getContentPane(  ).add( new JScrollPane( table ) );
    frame.pack(); frame.show(  );
  
public voidsetValueAt(java.lang.Object value, int row, int col)

    data[row][col] = new Expression( (String)value );
    fireTableDataChanged(  );