Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>isCellEditable(int row, int col)</strong> 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.</p> <pre><code>// 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) </code></pre> <p>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.</p> <pre><code>// 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(); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload