Getting the selected row through AbstractTableModel

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?

+5
source share
4 answers

TableModel refers only to data, ListSelectionModel refers to what is currently selected, so you cannot get the selected row from TableModel.

+6
source

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
+13

ListSelectionModel, TableModel, ... :-( ( ).

0

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());
0
source

All Articles