user4288844
user4288844

Reputation:

How to only allow one row at a time to be selected in a JTable?

I was wondering what the best way is to make it so that only one row at a time can be selected in a JTable? Is there a method to set this which I have missed or do I need to override it is some way?

I am using Oracle JDK 8.

Upvotes: 1

Views: 536

Answers (1)

c0der
c0der

Reputation: 18792

You need to:

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

Upvotes: 1

Related Questions