Selecting multiple rows of JTable

java, jtable, swing

Solution

You need to allow multiple selection:

table.setRowSelectionAllowed(true);
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

Then you need to write appropriate selection listener. It's a bit harder, try to find in google related solutions. You can look at an example of selection listener.

Problem

I'm currently using JTable to show the contents in database. I want to provide the facility for user so that he can select the number of rows he wants using shift+arrow key and then later on delete those records using the option provided for deletion. Please provide a small example.

Original source