tags:

views:

178

answers:

4

Hello,

I would like to know if it's possible to view my values through JTable and then edit them through there?

A: 

Yes, but without more information i can't help you more. See the JTable tutorial

Telcontar
+1  A: 

Sure it's possible just have TableModel.isCellEditable() return true, and if necessary set a TableCellEditor.

Michael Borgwardt
+1  A: 

isCellEditable(int row, int col) This method determines which rows and columns the user is allowed to modify. Since this method returns a Boolean, if all cells are editable it simply returns a true. To prevent a JTable from editing a particular column or row value, it returns a false from this method. The following code enables only column one to display while allowing the rest of the columns to be modified.

// Make column one noneditable

while allowing the user to edit at
all // other columns.
If (col == 1){
return false;
}
else{
return true;
}

public void setValueAt(Object value, int row, int col)

When the user makes changes to an editable cell, the Table Model is notified via this method. The new value, as well as the row and column it occurred in, is passed as arguments to this method. If the original data is coming from a database, this method becomes important. As you'll see, data retrieved from a database is held locally within the Table Model, usually as vectors. When the user changes a cell value in a JTable, the corresponding data in the Table Model isn't automatically changed. It's your responsibility to add code in this event to ensure that the data in the Table Model is the same as the data in the JTable. This becomes important when code is added to update the database. The following code updates the data (held in an array of objects) in the Table Model with the new value that the user just entered in the JTable.

// Update the array of objects with the changes the user has just entered in a cell. Then notify all listeners (if any) what column and row has changed. Further processing may take place there.

rowData[row][col] = value;
fireTableDataChanged();
harigm
A: 

Yes it is possible.Basically the jtable is editable.you can check through the TableModel.isCellEditable() method. After editing it you can store the table value in the two dimensional array and store in database. int i; int j;

    String tableData = new String[row count][column count];

    for(i = 0; i < row count; i++)
    {
        for(j = 0; j < 3; j++)
        {
            tableData[i][j] = table.getValueAt(i, j).toString();
        }
    }
Arivu2020