FileDocCategorySizeDatePackage
SpreadsheetModel.javaAPI DocExample3042Sat Apr 23 22:35:40 BST 2005None

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!");
    JTable table = new JTable( new SpreadsheetModel(15, 5) );
    table.setPreferredScrollableViewportSize( table.getPreferredSize() );
    table.setCellSelectionEnabled(true);
    frame.getContentPane().add( new JScrollPane( table ) );
	frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    frame.pack(); 
	frame.setVisible(true);
  
public voidsetValueAt(java.lang.Object value, int row, int col)

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