Related to checkbox in jtable

147 views Asked by At

I am using a table to display data.

I am providing checkbox to each row of a table to perform some operations based on selection. When I did like that, I am able to check multiple rows.

But my requirement is, at any point of time I should check only one checkbox. To be precise, I need the behavior of Buttongroup to all checkboxes in table.

How can I do this?

2

There are 2 answers

0
Robin On

If you really want to use checkboxes, I assume your TableModel holds a boolean for those checkboxes. It should be trivial to move the logic for the single selection to the TableModel.

If you do not need the checkboxes but just want to operate on the selected rows (see JTable#getSelectedRows), you can adjust the ListSelectionModel which is present on the JTable to only allow for single selection (see ListSelectionModel#SINGLE_SELECTION)

0
trashgod On

CheckOne is a complete example that simply clears all check boxes in a specific column and sets the new value. This related example uses JRadioButton.