How do I stop my JTable model from being edited? I'm using a DefaultTableModel and the only way I desire new rows to be entered is via the addRow method.

Jan Borchers

Override the isCellEditable method to prevent editing:


public class MyModel extends DefaultTableModel {
  public boolean isCellEditable(int row, int col) {
    return false;
  }
}

JTable will ask its model if it's ok to edit cells by calling this method. If you want to allow some rows, columns, or particular cells to be editable, change the above method to return true or false depending on the (row,column) passed in.

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact