May 1st, 2003, 06:21 PM
Radiobuttons in JTable
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.
Does anybody have a better idea?
May 1st, 2003, 06:39 PM
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:
Color...........Red, Blue, Green
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!
May 2nd, 2003, 03:43 AM
Click Here to Expand Forum to Full Width