views:

372

answers:

2

Hi, I'm doing a mini project using JTable.

I used the Vector type for the row values. For example, public Vector textData = new Vector();. The problem is when I edit the cells in the JTable, it is editable but not keeping the changed value. That is, when I enter data in 1 cell and move on to next cell, the previous data is not updated.

Is it possible to edit cells when declared as Vector?

A: 

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; }

harshit
+1  A: 

The type of the model you use does not really matter. What you need to do is basically notify your model that the data has changed after the edit. Check out the How to Use Tables for some examples.

Bogdan