-2

I'm doing a project that requires Jtable. However I'm using 3 Jtables. How am I able to make the third table cell editable while the first 2 remain uneditable?

The first 2 table are in a same Jpanel, while the third table on the other hand is on another Jpanel.

Here is my code for my FoodTableModel :

public boolean isCellEditable(int row, int column) {
    return true;
}   

@Override
public void setValueAt(Object value, int row, int col) {
    data[row][col] = value;
    fireTableCellUpdated(row, col);
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ng Wei Ze
  • 1
  • 4
  • Always a good read: [How to Use Tables](http://docs.oracle.com/javase/tutorial/uiswing/components/table.html) – Kai Jan 28 '15 at 09:14

1 Answers1

0

You could add a flag in your custom table model, and use it like

public boolean isCellEditable(int row, int column){

    if(cellEditable) {   
        return true;
    }

    return false;
} 

Check this answer for more details.

Community
  • 1
  • 1
Salah
  • 8,567
  • 3
  • 26
  • 43
  • Thanks for the reply! I will take note. mind if i ask another question? How do i validate the input such that it will only contain integer only? – Ng Wei Ze Jan 28 '15 at 09:31
  • Add a validation at the beginning of the `setValueAt` method. – Salah Jan 28 '15 at 09:51