0

I have a JTable in which one column is a checkbox. I want to let the user edit the checkbox by mouse drag: if they clicked one checkbox and drag mouse into other checkbox, they will get the same result with the first checkbox clicked.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
Ives
  • 505
  • 1
  • 4
  • 14
  • 1
    If you want to use mouse hover to edit checkbox, then why you are using drag option? because hovering over the rows makes you select or deselect the check boxes. Will you please elaborate more on requirement. – Sandeep Kokate Aug 22 '16 at 05:15
  • sorry, i means mouse hover, when you clicked one checkbox and still press mouse button then move into other checkBox they will be affected – Ives Aug 22 '16 at 07:59

1 Answers1

1

One approach is to specify ListSelectionModel.MULTIPLE_INTERVAL_SELECTION for the table's selection model, as shown here. Click and drag to select contiguous rows, or add the shift, control or command modifiers to select disparate rows. In a suitable Action, update the TableModel to reflect the selection, as shown here. The JTable will update itself in response.

image

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • thank you,but I want to edit it without press ctrl or shift – Ives Aug 24 '16 at 03:04
  • @Ives: You can select contiguous rows with click and drag; only multiple interval selection requires modifier keys. – trashgod Aug 24 '16 at 09:31
  • yes, I use MULTIPLE_INTERVAL_SELECTION, but I disabled rows select by drag, because I have drag and drop too,it will confused user , so if want MULTIPLE_INTERVAL_SELECTION work ,you have to press ctrl or shift – Ives Aug 25 '16 at 02:03
  • You might need a custom `ListSelectionModel`. – trashgod Aug 26 '16 at 01:08