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?
Use the
setSelectionMode()method fromListSelectionModelinterface, and set the selection mode toListSelectionModel.SINGLE_SELECTION.This will configure
JTableto work with one row at a time selection, blocking selection of multiple rows.To select single cells, combine the above with
setColumnSelectionAllowed(true)onTableColumnModel, and you should get what you need.