0

I am trying to implement a Jtable which includes three check-box tables like this:

image

Can you tell me how to set a single selection group of checkboxes which only allows 1 selected check-box in a single row at any time?

kleopatra
  • 51,061
  • 28
  • 99
  • 211
gncvnvcnc
  • 45
  • 2
  • 5

1 Answers1

-1

I know of nothing out-of-the-box for doing this. I´d have a TableModelListener check these columns every time a change is made and call setValueAt on the checkboxes as needed.

Jannis Alexakis
  • 1,279
  • 4
  • 19
  • 38
  • Ok but how would you go to check from the three boolean values (returned from getValueAt for each CheckBox) to get if there are 2 values with a certain value(false) and another one(true)? – gncvnvcnc Apr 09 '13 at 07:30
  • With getColumn() you get the column that fired the TableModelevent. If it is one of the checkboxes, you check whether it has been selected or deselected. If it has been selected, you change the values of the other two checkboxes to false. That would allow all three checkboxes to be false. If you always need one to be true, you have to check the states of the checkboxes with if-else clauses in such a way that the user is never allowed to deselect all three or select more than one. – Jannis Alexakis Apr 09 '13 at 07:40
  • no, keeping the constraints of the internal data (like only one boolean true in several boolean values for a given row) is the inherent responsibility of the model, not some external listener. – kleopatra Apr 19 '13 at 13:24