Class RadioButton

All Implemented Interfaces:
IsEditor<LeafValueEditor<Boolean>>, HasAllDragAndDropHandlers, HasAllFocusHandlers, HasAllGestureHandlers, HasAllKeyHandlers, HasAllMouseHandlers, HasAllTouchHandlers, HasBlurHandlers, HasClickHandlers, HasDoubleClickHandlers, HasDragEndHandlers, HasDragEnterHandlers, HasDragHandlers, HasDragLeaveHandlers, HasDragOverHandlers, HasDragStartHandlers, HasDropHandlers, HasFocusHandlers, HasGestureChangeHandlers, HasGestureEndHandlers, HasGestureStartHandlers, HasKeyDownHandlers, HasKeyPressHandlers, HasKeyUpHandlers, HasMouseDownHandlers, HasMouseMoveHandlers, HasMouseOutHandlers, HasMouseOverHandlers, HasMouseUpHandlers, HasMouseWheelHandlers, HasTouchCancelHandlers, HasTouchEndHandlers, HasTouchMoveHandlers, HasTouchStartHandlers, HasAttachHandlers, HasValueChangeHandlers<Boolean>, HasHandlers, HasDirectionEstimator, HasSafeHtml, EventListener, TakesValue<Boolean>, Focusable, HasDirectionalSafeHtml, HasDirectionalText, HasEnabled, HasFocus, HasHTML, HasName, HasText, HasValue<Boolean>, HasVisibility, HasWordWrap, IsWidget, SourcesClickEvents, SourcesFocusEvents, SourcesKeyboardEvents, SourcesMouseEvents

public class RadioButton extends CheckBox
A mutually-exclusive selection radio button widget. Fires ClickEvents when the radio button is clicked, and ValueChangeEvents when the button becomes checked. Note, however, that browser limitations prevent ValueChangeEvents from being sent when the radio button is cleared as a side effect of another in the group being clicked.

Built-in Bidi Text Support

This widget is capable of automatically adjusting its direction according to its content. This feature is controlled by CheckBox.setDirectionEstimator(boolean) or passing a DirectionEstimator parameter to the constructor, and is off by default.

CSS Style Rules

.gwt-RadioButton
the outer element

Example

public class RadioButtonExample implements EntryPoint {

  public void onModuleLoad() {
    // Make some radio buttons, all in one group.
    RadioButton rb0 = new RadioButton("myRadioGroup", "foo");
    RadioButton rb1 = new RadioButton("myRadioGroup", "bar");
    RadioButton rb2 = new RadioButton("myRadioGroup", "baz");

    // Check 'baz' by default.
    rb2.setChecked(true);

    // Add them to the root panel.
    FlowPanel panel = new FlowPanel();
    panel.add(rb0);
    panel.add(rb1);
    panel.add(rb2);
    RootPanel.get().add(panel);
  }
}

  • Field Details

    • DEFAULT_DIRECTION_ESTIMATOR

      public static final DirectionEstimator DEFAULT_DIRECTION_ESTIMATOR
  • Constructor Details

    • RadioButton

      @UiConstructor public RadioButton(String name)
      Creates a new radio associated with a particular group name. All radio buttons associated with the same group name belong to a mutually-exclusive set. Radio buttons are grouped by their name attribute, so changing their name using the setName() method will also change their associated group.
      Parameters:
      name - the group name with which to associate the radio button
    • RadioButton

      public RadioButton(String name, SafeHtml label)
      Creates a new radio associated with a particular group, and initialized with the given HTML label. All radio buttons associated with the same group name belong to a mutually-exclusive set. Radio buttons are grouped by their name attribute, so changing their name using the setName() method will also change their associated group.
      Parameters:
      name - the group name with which to associate the radio button
      label - this radio button's html label
    • RadioButton

      public RadioButton(String name, SafeHtml label, HasDirection.Direction dir)
      Parameters:
      name - the group name with which to associate the radio button
      label - this radio button's html label
      dir - the text's direction. Note that DEFAULT means direction should be inherited from the widget's parent element.
      See Also:
    • RadioButton

      public RadioButton(String name, SafeHtml label, DirectionEstimator directionEstimator)
      Parameters:
      name - the group name with which to associate the radio button
      label - this radio button's html label
      directionEstimator - A DirectionEstimator object used for automatic direction adjustment. For convenience, DEFAULT_DIRECTION_ESTIMATOR can be used.
      See Also:
    • RadioButton

      public RadioButton(String name, String label)
      Creates a new radio associated with a particular group, and initialized with the given HTML label. All radio buttons associated with the same group name belong to a mutually-exclusive set. Radio buttons are grouped by their name attribute, so changing their name using the setName() method will also change their associated group.
      Parameters:
      name - the group name with which to associate the radio button
      label - this radio button's label
    • RadioButton

      public RadioButton(String name, String label, HasDirection.Direction dir)
      Parameters:
      name - the group name with which to associate the radio button
      label - this radio button's label
      dir - the text's direction. Note that DEFAULT means direction should be inherited from the widget's parent element.
      See Also:
    • RadioButton

      public RadioButton(String name, String label, DirectionEstimator directionEstimator)
      Parameters:
      name - the group name with which to associate the radio button
      label - this radio button's label
      directionEstimator - A DirectionEstimator object used for automatic direction adjustment. For convenience, DEFAULT_DIRECTION_ESTIMATOR can be used.
      See Also:
    • RadioButton

      public RadioButton(String name, String label, boolean asHTML)
      Creates a new radio button associated with a particular group, and initialized with the given label (optionally treated as HTML). All radio buttons associated with the same group name belong to a mutually-exclusive set. Radio buttons are grouped by their name attribute, so changing their name using the setName() method will also change their associated group.
      Parameters:
      name - name the group with which to associate the radio button
      label - this radio button's label
      asHTML - true to treat the specified label as HTML
  • Method Details

    • onBrowserEvent

      public void onBrowserEvent(Event event)
      Overridden to send ValueChangeEvents only when appropriate.
      Specified by:
      onBrowserEvent in interface EventListener
      Overrides:
      onBrowserEvent in class Widget
      Parameters:
      event - the event received
    • setName

      public void setName(String name)
      Change the group name of this radio button. Radio buttons are grouped by their name attribute, so changing their name using the setName() method will also change their associated group. If changing this group name results in a new radio group with multiple radio buttons selected, this radio button will remain selected and the other radio buttons will be unselected.
      Specified by:
      setName in interface HasName
      Overrides:
      setName in class CheckBox
      Parameters:
      name - name the group with which to associate the radio button
    • sinkEvents

      public void sinkEvents(int eventBitsToAdd)
      Description copied from class: Widget
      Overridden to defer the call to super.sinkEvents until the first time this widget is attached to the dom, as a performance enhancement. Subclasses wishing to customize sinkEvents can preserve this deferred sink behavior by putting their implementation behind a check of isOrWasAttached():
       @Override
       public void sinkEvents(int eventBitsToAdd) {
         if (isOrWasAttached()) {
           /* customized sink code goes here */
         } else {
           super.sinkEvents(eventBitsToAdd);
        }
      } 
      Overrides:
      sinkEvents in class CheckBox
      Parameters:
      eventBitsToAdd - a bitfield representing the set of events to be added to this element's event set
      See Also:
    • ensureDomEventHandlers

      protected void ensureDomEventHandlers()
      No-op. CheckBox's click handler is no good for radio button, so don't use it. Our event handling is all done in onBrowserEvent(com.google.gwt.user.client.Event)
      Overrides:
      ensureDomEventHandlers in class CheckBox