Spreadsheet extends AbstractTableModel { @Override public void setValueAt(Object value, int row, int column) { try { value = Double.parseDouble(value.toString()); } catch (NumberFormatException e) { } if (value.equals("true") || value.equals("false")) { value = Boolean.parseBoolean(value.toString()); } if (value.getClass() == Integer.class) { data[row][column] = new NumberCell(row, column); Integer temp_integer = (Integer) value; data[row][column].setCell(temp_integer.doubleValue()); } else if (value.getClass() == Double.class) { data[row][column] = new NumberCell(row, column); data[row][column].setCell(value); } else if (value.getClass() == Boolean.class) { data[row][column] = new BooleanCell(row, column); data[row][column].setCell((Boolean) value); } else if (value.getClass() == String.class) { data[row][column] = new StringCell(row, column); data[row][column].setCell((String) value); } else { data[row][column] = new StringCell(row, column); data[row][column].setCell(""); } fireTableCellUpdated(row, column); } Spreadsheet(int rows, int columns); @Override int getRowCount(); @Override int getColumnCount(); @Override // Override this method so that all the Jtable cells become editable: boolean isCellEditable(int rowIndex, int columnIndex); @Override // Return the value inside the selected Cell (depending on its type): Object getValueAt(int row, int column); @Override void setValueAt(Object value, int row, int column); Cell getCell(int row, int column); void useFunction(Cell[] input_cells, String function, Cell output_cell); void createChart();  }
@Test public void testSetValueAt() { spreadsheet.setValueAt("blah", 1, 1); assertEquals("blah", (String)spreadsheet.getValueAt(1, 1)); }