You are using a TableModel, which implements isCellEditable by always returning true. Your desired behaviour can be achieved by writing a Table Model that always returns false. Example:
public class MyTableModel extends DefaultTableModel {
public MyTableModel(Vector data, Vector columnNames) {
setDataVector(data, columnNames);
}
@Override
public boolean isCellEditable(int row, int column) {
return false;
}
}
and add this line to your code:
table.setModel(new MyTableModel(data, columnNames));
Alternative
If you wanna stick to the double array, try:
JTable table = new JTable(new AbstractTableModel() {
public String getColumnName(int column) { return columnNames[column].toString(); }
public int getRowCount() { return dataValues.length; }
public int getColumnCount() { return columnNames.length; }
public Object getValueAt(int row, int col) { return dataValues[row][col]; }
public boolean isCellEditable(int row, int column) { return false; }
});
For that to work, you will need to make your variables columnNames
and dataValues
final
.