Reputation: 49
jtable get selected row value i want to make it so when u click on a row it will get the row number and put it into a variable.
int Test1 = 0;
This is in my button Listener
myList.remove(Test1);
but what do i need to find what row is selected.
any help would be grateful thanks
i used this in the end
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
sel = table.getSelectedRow();
}
});
Upvotes: 0
Views: 1040
Reputation: 2348
Check the API documentation, JTable has following methods
getSelectedRow()
getSelectedRows()
getSelectedRowCount()
If your table is enabled for sorting and you want to get data from your TableModel then do not forget to call convertRowIndexToModel(int selectedRow)
Upvotes: 1