vidya
vidya

Reputation:

cell editing in JTable

I'm doing a project using JTable, i want to make my table cells editable. I used,

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

My problem is, the cells are editable but once after entering data into one cell and move on to the next, the previous data gets erased... kindly any one help me...

Upvotes: 3

Views: 12977

Answers (2)

amila
amila

Reputation:

public void setValueAt(Object value, int row, int col) {
    datum[row][col]=value;
    fireTableCellUpdated(row, col);
}

Upvotes: 0

user57697
user57697

Reputation: 388

Override setValueAt(Object value, int row, int col) method as well. It should store entered data, so getValueAt(int row, int col) method can return new value. Something like this:

private String[][] data;
public Object getValueAt(int row, int col) {
    return data[row][col];
}
public void setValueAt(Object value, int row, int col) {
    data[row][col] = value;
}

Upvotes: 7

Related Questions