/* * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * * * * * * * * * * * * * */ package javafx.scene.control; import javafx.geometry.Pos; import com.sun.javafx.scene.control.skin.RadioButtonSkin; import javafx.beans.value.WritableValue; import javafx.css.StyleableProperty; import javafx.scene.AccessibleAttribute; import javafx.scene.AccessibleRole; /** *
RadioButtons create a series of items where only one item can be * selected. RadioButtons are a specialized {@link ToggleButton}. * When a RadioButton is pressed and released a {@link javafx.event.ActionEvent} * is sent. Your application can perform some action based * on this event by implementing an {@link javafx.event.EventHandler} to * process the {@link javafx.event.ActionEvent}.
* ** Only one RadioButton can be selected when placed in a {@link ToggleGroup}. * Clicking on a selected RadioButton will have no effect. A RadioButton that is not * in a ToggleGroup can be selected and unselected. By default a RadioButton is * not in a ToggleGroup. Calling {@code ToggleGroup.getSelectedToggle()} * will return you the RadioButton that has been selected. *
* *
*
* ToggleGroup group = new ToggleGroup();
* RadioButton button1 = new RadioButton("select first");
* button1.setToggleGroup(group);
* button1.setSelected(true);
* RadioButton button2 = new RadioButton("select second");
* button2.setToggleGroup(group);
*
*
* @since JavaFX 2.0
*/
public class RadioButton extends ToggleButton {
/***************************************************************************
* *
* Constructors *
* *
**************************************************************************/
/**
* Creates a radio button with an empty string for its label.
*/
public RadioButton() {
initialize();
}
/**
* Creates a radio button with the specified text as its label.
*
* @param text A text string for its label.
*/
public RadioButton(String text) {
setText(text);
initialize();
}
private void initialize() {
getStyleClass().setAll(DEFAULT_STYLE_CLASS);
setAccessibleRole(AccessibleRole.RADIO_BUTTON);
// alignment is styleable through css. Calling setAlignment
// makes it look to css like the user set the value and css will not
// override. Initializing alignment by calling set on the
// CssMetaData ensures that css will be able to override the value.
((StyleableProperty