Is it possible to get the selected row index from my table?
My object already knows about the table model. Instead of passing a link to a table, can I get the selected index using the model?
TableModel refers only to data, ListSelectionModel refers to what is currently selected, so you cannot get the selected row from TableModel.
MrWiggles, ListSelectionModel, . JTable . .., convertRowIndexToModel:)
JTable JavaDoc:
int[] selection = table.getSelectedRows(); for (int i = 0; i < selection.length; i++) { selection[i] = table.convertRowIndexToModel(selection[i]); } // selection is now in terms of the underlying TableModel
ListSelectionModel, TableModel, ... :-( ( ).
You can get the index from a linked table, and then you can use it to control the table model. For example, if I want to delete a row in my table model:
myTableModel.removeValueAt(myTable.getSelectedRow());