ToggleButton
A JToggleButton, a two-state button that stays in until clicked again.
The selected state is controlled via selected + onSelectedChange: the button shows whatever selected holds, and a click toggles it, reporting the new state through onSelectedChange. A state the caller pushes in is reflected without echoing back through the callback. A toggle the caller does not answer with a matching selected does not stand: the button is back on the declared state before the click is painted.
ToggleButton(text = "Bold", selected = bold, onSelectedChange = { bold = it })Parameters
the text to display on the button
whether the button is in its selected state
callback invoked with the selected state when the button is activated
the SwingModifier applied to the underlying component
See also
A ToggleButton driven by a raw ActionListener instead of an onSelectedChange lambda. The listener is attached as-is and removed on the same instance; pass a stable instance (e.g. remember {}) to avoid churn.
Parameters
the text to display on the button
whether the button is in its selected state
the listener notified when the button is toggled
the SwingModifier applied to the underlying component