Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4292804

DefaultTableModel doc confusion between isCellEditable and setValueAt



    • kestrel
    • sparc
    • solaris_2.6


      Confusion between doc and implementation: In the source code
      isCellEditable(int row,int column) will always return true, because we do nothing with row,column values. If a user creates own model extended from
      DefaultTableModel and then they override isCellEditable to always return
      false, when table is visible the view looks correct and the user can't type in new values but they can make model.setValueAt() calls to change the values under the hood. Provided they had some event to set the value. I also understand that in my extended class I can override setValueAt() method to do nothing. The code for setValueAt() in DefaultTableModel should handle the cases where isCellEditable would return false and do nothing.

      Java docs provided:

      public boolean isCellEditable(int row,int column)

            Returns true if the cell at row and column is editable. Otherwise, the setValueAt() on the cell will not
            change the value of that cell.
                  isCellEditable in class AbstractTableModel
                  row - the row whose value is to be looked up
                  column - the column whose value is to be looked up
                  true if the cell is editable.
            See Also:
                  setValueAt(java.lang.Object, int, int)

      public void setValueAt(Object aValue,
                             int row,
                             int column)

            Sets the object value for the cell at column and row. aValue is the new value. This method will generate a
            tableChanged() notification.
                  setValueAt in class AbstractTableModel
                  aValue - the new value. This can be null.
                  row - the row whose value is to be changed
                  column - the column whose value is to be changed
                  ArrayIndexOutOfBoundsException - if an invalid row or column was given.
      gary.collins@East 1999-11-18


      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      import javax.swing.table.*;
      import java.util.*;
      import javax.accessibility.*;

      public class SetValueAt extends JFrame {
        static boolean tests = true;
        static int count = 0;
        private int rows=3, cols=5;
        private Object[] rowData = new Object[cols];
        private Vector vRowData = new Vector(cols);
        private MyDefaultTableModel model = new MyDefaultTableModel();
        private JTable table = new JTable(model);
        public SetValueAt() {
          for(int c=0; c < cols; ++c)
            model.addColumn("Column " + Integer.toString(c));
          for(int r=0; r < rows; ++r) {
            for(int c=0; c < cols; ++c) {
      rowData[c] = "(" + r + "," + c + ")";
          getContentPane().add(new JScrollPane(table),
        public static void main(String args[]) {
          SetValueAt t = new SetValueAt();
          // Below 2 lines invokes and ActionEvent. Local actionPerformed method traps call and invokes
          // insertRow call.
          ActionEvent ae = new ActionEvent(t, ActionEvent.ACTION_PERFORMED, "Test 1");

        // This method is where the actual test occurs.
        public void actionPerformed(ActionEvent evt) {
          String cmd = evt.getActionCommand();

          if (cmd.equals("Test 1")) {
            System.out.println("Is the Cell's editable:="+model.isCellEditable(2,2));
            System.out.println("Cell ValueAt(2,2):="+model.getValueAt(2,2));
            System.out.println("Cell ValueAt(2,2) After setValueAt(2,2) call:="+model.getValueAt(2,2));
          if (count==2) {
      class MyDefaultTableModel extends DefaultTableModel {
        public MyDefaultTableModel() {
        public boolean isCellEditable(int row, int column) {
          return false;


      gary.collins@East 1999-11-18




            sharonz Sharon Zakhour (Inactive)
            collins Gary Collins (Inactive)
            0 Vote for this issue
            0 Start watching this issue