ahh, sorry, i thought you just wanted to test if a cell was editable, not disable and enabled editing full stop on the table...
if i wanted this kind of functionality i personally would write a TableModel Delegate, that could accept anoter TableModel, and add methods that would allow me to set the entire table editable or not.
Code:
public class MyTable extends JTable{
ModelDelegate delegate = new ModelDelegate();
boolean editable = true;
public void setModel(TableModel dataModel) {
delegate.setModel(dataModel);
super.setModel(this.delegate);
}
public void setEditable(boolean editable){
this.editable = editable;
}
private class ModelDelegate implements TableModel{
TableModel model;
public void setModel(TableModel model){
this.model = model;
}
public void addTableModelListener(TableModelListener l) {
model.addTableModelListener(l);
}
public boolean equals(Object obj) {
return model.equals(obj);
}
public Class getColumnClass(int columnIndex) {
return model.getColumnClass(columnIndex);
}
public int getColumnCount() {
return model.getColumnCount();
}
public String getColumnName(int columnIndex) {
return model.getColumnName(columnIndex);
}
public int getRowCount() {
return model.getRowCount();
}
public Object getValueAt(int rowIndex, int columnIndex) {
return model.getValueAt(rowIndex, columnIndex);
}
public int hashCode() {
return model.hashCode();
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
/**
* Test to see if the Table is editable
* if so call in the model we are delegtaing to
*/
if(editable){
return model.isCellEditable(rowIndex, columnIndex);
}else{
/**
* Return false.
*/
return editable;
}
}
public void removeTableModelListener(TableModelListener l) {
model.removeTableModelListener(l);
}
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
model.setValueAt(aValue, rowIndex, columnIndex);
}
}
}
would that do what you wanted?