tags:

views:

12

answers:

0

Can I get an explanation of how the setValueAt method here works ?

final DefaultTableModel model = new DefaultTableModel(data, columns) 
   {
      @Override
      public boolean isCellEditable(int row, int column) 
      {
          switch (column) 
          {
           case 0: return true;
           case 1: return true;
           case 2: return TriState.NONE != getValueAt(row, 2);
          }
        return false;
      }

      @Override
      public Class<?> getColumnClass(int columnIndex) 
      {
         switch (columnIndex) 
         {
            case 0: return Boolean.class;
            case 1: return Boolean.class;
            case 2: return TriState.class;
            //case 2: return double.class;
         }
         return null;
      }

    @Override
    public void setValueAt(Object value, int row, int column) 
    {
        if (column == 2) 
        {
            if (value instanceof Boolean) 
            {
                value = Boolean.TRUE.equals(value) ? TriState.TRUE : TriState.FALSE;
            }
        }
        super.setValueAt(value, row, column);
        if (column == 0) 
        {
            if (Boolean.TRUE.equals(value)) 
            {
                setValueAt(TriState.FALSE, row, 2);
            } 
            else 
            {
                setValueAt(TriState.NONE, row, 2);
            }
        }
    }


   };