I would like to implement a table where the first column is a Radiobutton that serves as a GroupSelector. The second and third column would be a list of names and a checkbox. The idea is to first select a group (say animals, humans) via the radiobuttons, and then within that group use the checkboxes to select individuals in that group (say dogs and cats). When one group is selected, the other group should not be editable (checkboxes disabled).
I tried to use a double JTable. The First one with 2 cols, where the second col is another JTable with the names and checkboxes. However, I had trouble selecting the checkboxes that way.
Another idea was to have a radiobutton per row, and hide and disable the ones that are in the same group.
A third idea was to just one table, and put the names/checkboxes in a panel (one per group) and add them to the respec. columns.
None of this seems to really be the greatest solution and I had trouble implementing it.
How about two JLists and a JTable. The first JList would list groups, and be set to a SINGLE_SELECTION_MODE. The second JList would be dynamic (allowing multiple selection), showing only members of the group chosen in the first JList (via a ListSelectionListener). Finally, a JTable would capture the state of the lists at the click of a JButton. After a few clicks, the table might look like:
Group...........Names
--------.......---------------
Color...........Red, Blue, Green
Animals........Dog, Cat
Color...........Yellow, Black
Humans........Dave, George, Joey
Maybe not as elegant as you described, but it would be easy to implement, and user friendly.
Then again, I might have misunderstood your intent!
Bookmarks