Reputation: 1037
I have a JTable consisting of multiple rows and columns. I want to make the cells selectable, but only in one row at a time. So for example, when I click on the cell in third row and the fifth column, I can pull the mouse to the left or right and select more cells, but only in this specific row and not in the row above or below.
How can I do this?
Upvotes: 3
Views: 6679
Reputation: 15699
Use the setSelectionMode()
method from ListSelectionModel
interface, and set the selection mode to ListSelectionModel.SINGLE_SELECTION
.
This will configure JTable
to work with one row at a time selection, blocking selection of multiple rows.
To select single cells, combine the above with setColumnSelectionAllowed(true)
on TableColumnModel
, and you should get what you need.
Upvotes: 7