user3504020
user3504020

Reputation: 49

Getting selected row value out of a jtable

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

Answers (1)

jdiver
jdiver

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

Related Questions