ToggleButton

@Composable
fun ToggleButton(text: @Nls String, selected: Boolean, onSelectedChange: (Boolean) -> Unit, modifier: SwingModifier = SwingModifier)

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

text

the text to display on the button

selected

whether the button is in its selected state

onSelectedChange

callback invoked with the selected state when the button is activated

modifier

the SwingModifier applied to the underlying component

See also


@Composable
fun ToggleButton(text: @Nls String, selected: Boolean, actionListener: ActionListener, modifier: SwingModifier = SwingModifier)

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

text

the text to display on the button

selected

whether the button is in its selected state

actionListener

the listener notified when the button is toggled

modifier

the SwingModifier applied to the underlying component

See also