Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2002
    Posts
    2

    Unanswered: JTable isCellEditable method

    Hi,
    How can I make a column with Boolean values in a JTable Editable?
    I have something like this, but it doesn't work:

    data = new Object[][]{
    {"1","11","A","","","",new Integer(14), new Boolean(true)},
    {"2","22","","B","","",new Integer(1),new Boolean(false)}};

    column = new Object[]{"fixed 1","fixed 2","a","b","c","d","e","f"};

    AbstractTableModel fixedModel = new AbstractTableModel() {
    public int getColumnCount() { return column.length; }
    public int getRowCount() { return data.length;}
    public String getColumnName(int col) {
    return (String)column[col];
    }
    public Object getValueAt(int row, int col) {
    return data[row][col];
    }
    public Class getColumnClass(int col) {
    if (col == 7)
    return Boolean.class;
    else if (col == 6)
    return Integer.class;
    else
    return Object.class;
    }
    public boolean isCellEditable(int row, int col) {
    if (col == 7)
    return true;
    else
    return false;
    }
    }

    JTable jTable1 = new JTable(fixedModel);

    Thank you,
    Vermelh0

  2. #2
    Join Date
    Dec 2002
    Posts
    2
    Hum, I think I found a solution through trial and error, but I don't understand it...
    My solution is to create a setValueAt method inside the AbstractTableModel class like this:

    public void setValueAt(Object value, int row, int col) {
    data[row][col] = value;
    super.setValueAt(value, row, col);
    }

    Now the part I don't understand is why I must create this method....
    Why doesn't the data array automatically update itself with the value?
    Thank you,
    V

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •