RadioGroup

@Composable
fun RadioGroup(selectedIndex: Int, onSelectionChange: (Int) -> Unit, modifier: SwingModifier = SwingModifier, axis: Int = BoxLayout.Y_AXIS, content: RadioGroupScope.() -> Unit)

A set of mutually exclusive choices, backed by a shared ButtonGroup, so at most one option is selected at a time.

Declare the choices in content; each option(...) becomes a JRadioButton laid out in the group's panel in call order. The selected option is controlled via selectedIndex (the zero-based position of the chosen option, or any out-of-range value such as -1 for no selection); clicking an option selects it and invokes onSelectionChange with its index, while external selectedIndex changes move the selection to match.

RadioGroup(selectedIndex = choice, onSelectionChange = { choice = it }) {
option("Small")
option("Medium")
option("Large")
}

A pick the caller does not answer with a matching selectedIndex is settled back onto the declared one, so the option shown selected is the one the composition holds.

Parameters

selectedIndex

the index of the selected option (controlled); an out-of-range value, such as -1, leaves every option unselected

onSelectionChange

callback invoked with the option's index when the user selects it

modifier

the SwingModifier applied to the group's panel

axis

the axis along which the options are arranged (a BoxAxis BoxLayout value); Y_AXIS - the default - stacks them in a column

content

declares the options; see RadioGroupScope

See also