I'm writing a TableCellEditor implementation which needs to fetch some data from underlying TableModel. In order to do that, I need row and column indices for TableModel.
What I'd like to know is whether the indices getTableCellEditorComponent() receives are view coordinates or model coordinates. In other words, are the table.convertRowIndexToModel()
and table.convertColumnIndexToModel()
calls in the following code necessary? Or is it ok to just pass those indicies to model.getValueAt()
directly?
class MyTableCellEditor implements TableCellEditor {
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
TableModel model = table.getModel();
// is this necessary?
int rowForQueryingModel = table.convertRowIndexToModel(row);
int colForQueryingModel = table.convertColumnIndexToModel(column);
Object valueFromModel = model.getValueAt(rowForQueryingModel, colForQueryingModel);
return createComponent(valueFromModel);
}
...
}