Home Button
Contents
Swing Logo

Swinging Duke
Feedback Button
Left ArrowRight Arrow

 

The JRadioButton API

This specification describes the API for the Swing JRadioButton class.

In Swing, a JRadioButton object is a component that displays both a radio-style button and a text label. When the radio button is pressed and released, an ItemEvent is sent to all registered ItemListeners to inform them that the radio button has been selected or deselected.

Radio buttons can be arranged in groups, which are instantiations of a class named JRadioButtonGroup. When a radio button is a member of a JRadioButtonGroup, Swing makes it possible for the user to select only one one radio button in the group at a time.


Features of JRadioButton Components

Swing allows you to position the label text that is associated with a JRadioButton component. Specifically, Swing supports two kinds of text positioning:


The JRadioButton Interface

The JRadioButton model interface is shared by JButton, JToggleButton, JCheckbox, and JRadioButton. The isSelected state is used by JToggleButton, JCheckbox, and RadioButton, but not by JButton.


public interface ButtonModel
{
  boolean isPressed();
  boolean isSelected();
  boolean isArmed();
  boolean isDisabled();
  boolean isRollover();
 
  public void setPressed(boolean b);
  public void setSelected(boolean b);
  public void setArmed(boolean b);
  public void setDisabled(boolean b);
  public void setRollover(boolean b);
 
    public void setKeyAccelerator(char aKey);
    public char getKeyAccelerator();
 
    public void setActionCommand(String s);
    public String getActionCommand();
 
    public void setGroup(ButtonGroup group);
    
    void addActionListener(ActionListener l);
    void removeActionListener(ActionListener l);
 
    void addItemListener(ItemListener l);
    void removeItemListener(ItemListener l);
 
    void addChangeListener(ChangeListener l);
    void removeChangeListener(ChangeListener l);
}


Events

JRadioButton components are a source of ItemEvents. By registering itself as an ItemListener of a radio button, an object can ensure that it will be notified when a radio button has been selected or deselected.

Arrows


Version 0.4. Last modified 09/04/97.
Copyright © 1995-97 Sun Microsystems, Inc. All Rights Reserved.

Sun's Home Page