As I see the source code of javax.swing.JTable
, this is found:
public Object getValueAt(int row, int column) {
return getModel().getValueAt(convertRowIndexToModel(row),
convertColumnIndexToModel(column));
}
The result of JTable#getModel()
returns an element that belongs to the TableModel
interface. This model can be indicated in the constructor of JTable
, since none is indicated, a default value will be used. I put the relevant code:
public JTable() {
this(null, null, null);
}
public JTable(TableModel dm, TableColumnModel cm, ListSelectionModel sm) {
//...
if (dm == null) {
dm = createDefaultDataModel();
}
setModel(dm);
}
//...
protected TableModel createDefaultDataModel() {
return new DefaultTableModel();
}
Therefore, the result of JTable#getValueAt
, assuming that you do not manually assign any TableModel
, will depend on the implementation of DefaultTableModel#getValueAt
, whose code is:
public Object getValueAt(int row, int column) {
Vector rowVector = (Vector)dataVector.elementAt(row);
return rowVector.elementAt(column);
}
Seeing that this model is based on Vector
is, the result of looking for an element whose indexes are not in the table, ArrayIndexOutOfBoundsException
will be obtained.
You can check the sources online at the following URLs:
If you want to browse all available rows in your JTable
, it would be best to use TableModel#getRowCount
:
TableModel tm = TabVentas.getModel();
for (int i = 0; i < tm.getRowCount(); i++) {
//hacer algo con este valor...
TabVentas.getValueAt(i, 0);
}