Sure, checkboxes allow multiple selection in general, but as I've said, I've come across lots of examples where applications use radio-like checkboxes to do precisely what Andy proposed: create a group of toggles where either one toggle or no toggle can be selected at any given time. I'm not saying that this is a great UX, I'm saying that this is a common thing in many applications. That's in stark contrast to a deselectable group of RadioButtons, which I haven't come across in any application that I know.
While one could use ToggleButtons for that, ToggleButtons are not CheckBoxes. They look different out of the box, and require unintuitive re-styling to make them look like CheckBoxes. My point is this: if it looks like a CheckBox, it should also _be_ a CheckBox. In this case, that's as easy as acknowledging that a CheckBox is, indeed, a Toggle. I don't think that the indeterminate state is a problem here. For the "group of one or zero toggles" scenario, one would simply disallow the indeterminate state. If the indeterminate state is allowed, no conflict occurs: upon automatic deselection, the ToggleGroup would set CheckBox.selected=false, while CheckBox.indeterminate would remain true. That doesn't make a lot of sense from a UI perspective, but it's not something that would happen by accident. After all, CheckBox.allowIndeterminate is false by default. On Sat, Jan 21, 2023 at 7:19 PM Nir Lisker <nlis...@gmail.com> wrote: > > We already have ToggleButton: > >> Unlike RadioButtons, ToggleButtons in a ToggleGroup do not attempt to force >> at least one selected ToggleButton in the group. >> >> That is, if a ToggleButton is selected, clicking on it will cause it to >> become unselected. >> >> With RadioButton, clicking on the selected button in the group will have no >> effect. > > > Checkboxes tend to allow multiple selection ("select all items that apply to > you"), which means they don't need to toggle each other, they are > independent. They also have indeterminate states, which I don't know how to > address regarding ToggleGroup selection policies. > > On Sat, Jan 21, 2023 at 6:33 PM Michael Strauß <michaelstr...@gmail.com> > wrote: >> >> My expectation with radio groups is that they may start out initially >> unselected, but once a selection has been made, no user interaction >> can unselect all toggles again. >> I don't see any compelling reason to change that. If the group needs >> to be reset to its initial state, that's as easy as calling >> `toggleGroup.selectToggle(null)`. >> >> However, what you're describing sounds to me like a group of >> checkboxes. I've seen this type of grouping many times in various >> applications, and checkboxes are generally understood to be >> deselectable. >> So my question is: why don't we instead have CheckBox implement >> Toggle, allowing it to be used with ToggleGroup? That would make it >> possible to create a deselectable group of toggles. >> >> On Fri, Jan 20, 2023 at 8:31 PM Andy Goryachev >> <andy.goryac...@oracle.com> wrote: >> > >> > Dear colleagues: >> > >> > >> > >> > In the context of a recent PR >> > >> > >> > >> > https://bugs.openjdk.org/browse/JDK-8237505 >> > >> > https://github.com/openjdk/jfx/pull/1002 >> > >> > https://stackoverflow.com/questions/57911107/javafx-togglegroup-not-functioning-properly-with-accelerators-radiomenuitem >> > >> > >> > >> > where a number of RadioMenuItems belonging to a toggle group are added to >> > the menu, we might want to add a new property to the ToggleGroup which >> > controls whether all items in a group can be deselected. >> > >> > >> > >> > If this property is set, a selected radio menu item can be deselected via >> > either keyboard accelerator or a mouse click. If not, then not only this >> > operation cannot be performed, but also the first item added to said >> > ToggleGroup gets automatically selected. >> > >> > >> > >> > This should allow for more flexibility in creating menus with >> > RadioMenuItems, but eliminate some boilerplate code required in such cases. >> > >> > >> > >> > The new logic would also affect any Toggle, such as ToggleButton. >> > >> > >> > >> > What do you think? Thank you. >> > >> > >> > >> > -andy