How do i get the values of multiple selection from a JTable

rafaelzm2000 picture rafaelzm2000 · Oct 4, 2012 · Viewed 7.3k times · Source

Can someone please provide a sample code or at least a method that I can use to get the string values of multiple selections in a JTable? I searched the web, but I found only examples of how to get values from a single selection. Based on that I tried to implement the code myself using loops, but it blew up on my face. Any help will be greatly appreciated.

Answer

Razvan picture Razvan · Oct 4, 2012

JTable has a method for that :

    int[] selection = table.getSelectedRows();

Of course, this method returns the indices of the selected rows. You can use these indices to get the values you want from the the table model.