globaltcad / swing-tree

A small DSL library for building Swing UIs
MIT License
6 stars 0 forks source link

Radio Buttons #86

Closed Mazi-S closed 4 months ago

Mazi-S commented 5 months ago

Currently it is a bit difficult to create a set of radio buttons and link them together. (Or am I missing something?)

Wouldn't it be nice to have a nice API in SwingTree to make this easier?

UI.radioButton(String text, T value, Var<T> current)

The provided value could be set to the property when the button is selected. On the other hand, the button could be deselected/selected when the property is updated.

Gleethos commented 5 months ago

Currently there are 3 ways of binding the radio button.

  1. Directly bind to a boolean property.
  2. Bind to an enum based property and if it is equal to one of the enums the selection is set accordingly.
  3. Supplying a common ButtonGroup through withButtonGroup(..)

Your proposal is a nice type agnostic extension of approach 2. which is currently only possible using isSelectedIf(..) methods. But there is no direct way of achieving this like the method UI.radioButton(String text, T value, Var<T> current) in your proposal.

I like the suggestion a lot and will add support for it.