Reading the remark of Kleopatra (his 2nd time he suggested to have a look at javax.swing.JXTable, and now I Am sorry I didn't have a look the first time :) ) I suggest you follow the link
I searched for an asnwer, and I combined several answers to my own solution: (however, not safe for all solutions, but understandable and quick impelmented, although I recommende to look at the link above)
You can keep it more flexible to set which column is editable or not later on, I used this for exmaple:
columnsEditable=new ArrayList<Integer>();
table=new JTable(new DefaultTableModel(){
@Override
public boolean isCellEditable(int row, int col) {
if(columnsEditable.isEmpty()){
return false;
}
if(columnsEditable.contains(new Integer(col))){
return true;
}
return false;
}
});
And I used this function to set editable or not:
public void setColumnEditable(int columnIndex,boolean editable){
if(editable){
if(!columnsEditable.contains(new Integer(columnIndex))){
columnsEditable.add(new Integer(columnIndex));
}
}else{
if(columnsEditable.contains(new Integer(columnIndex))){
columnsEditable.remove(new Integer(columnIndex));
}
}
}
Note: of course you have to define columnsEditable and JTable table global in this class:
private JTable table;
private ArrayList<Integer> columnsEditable;
Note 2: by default all columns are not editable, but that is my desired behaviour. If you whish otherwhise, either add all columns to columnsEditable or change the behaviour completely (make ArrayList columnsNonEditable