FileDocCategorySizeDatePackage
JToggleButton.javaAPI DocJava SE 5 API12248Fri Aug 26 14:57:56 BST 2005javax.swing

JToggleButton

public class JToggleButton extends AbstractButton implements Accessible
An implementation of a two-state button. The JRadioButton and JCheckBox classes are subclasses of this class. For information on using them see How to Use Buttons, Check Boxes, and Radio Buttons, a section in The Java Tutorial.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see {@link java.beans.XMLEncoder}.

beaninfo
attribute: isContainer false description: An implementation of a two-state button.
see
JRadioButton
see
JCheckBox
version
1.59 12/19/03
author
Jeff Dinkins

Fields Summary
private static final String
uiClassID
Constructors Summary
public JToggleButton()
Creates an initially unselected toggle button without setting the text or image.


                     
       
        this(null, null, false);
    
public JToggleButton(Icon icon)
Creates an initially unselected toggle button with the specified image but no text.

param
icon the image that the button should display

        this(null, icon, false);
    
public JToggleButton(Icon icon, boolean selected)
Creates a toggle button with the specified image and selection state, but no text.

param
icon the image that the button should display
param
selected if true, the button is initially selected; otherwise, the button is initially unselected

        this(null, icon, selected);
    
public JToggleButton(String text)
Creates an unselected toggle button with the specified text.

param
text the string displayed on the toggle button

        this(text, null, false);
    
public JToggleButton(String text, boolean selected)
Creates a toggle button with the specified text and selection state.

param
text the string displayed on the toggle button
param
selected if true, the button is initially selected; otherwise, the button is initially unselected

        this(text, null, selected);
    
public JToggleButton(Action a)
Creates a toggle button where properties are taken from the Action supplied.

since
1.3

        this();
	setAction(a);
    
public JToggleButton(String text, Icon icon)
Creates a toggle button that has the specified text and image, and that is initially unselected.

param
text the string displayed on the button
param
icon the image that the button should display

        this(text, icon, false);
    
public JToggleButton(String text, Icon icon, boolean selected)
Creates a toggle button with the specified text, image, and selection state.

param
text the text of the toggle button
param
icon the image that the button should display
param
selected if true, the button is initially selected; otherwise, the button is initially unselected

        // Create the model
        setModel(new ToggleButtonModel());

        model.setSelected(selected);

        // initialize
        init(text, icon);
    
Methods Summary
public javax.accessibility.AccessibleContextgetAccessibleContext()
Gets the AccessibleContext associated with this JToggleButton. For toggle buttons, the AccessibleContext takes the form of an AccessibleJToggleButton. A new AccessibleJToggleButton instance is created if necessary.

return
an AccessibleJToggleButton that serves as the AccessibleContext of this JToggleButton
beaninfo
expert: true description: The AccessibleContext associated with this ToggleButton.

        if (accessibleContext == null) {
            accessibleContext = new AccessibleJToggleButton();
        }
        return accessibleContext;
    
public java.lang.StringgetUIClassID()
Returns a string that specifies the name of the l&f class that renders this component.

return
String "ToggleButtonUI"
see
JComponent#getUIClassID
see
UIDefaults#getUI
beaninfo
description: A string that specifies the name of the L&F class

        return uiClassID;
    
protected java.lang.StringparamString()
Returns a string representation of this JToggleButton. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null.

return
a string representation of this JToggleButton.

        return super.paramString();
    
public voidupdateUI()
Resets the UI property to a value from the current look and feel.

see
JComponent#updateUI

        setUI((ButtonUI)UIManager.getUI(this));
    
private voidwriteObject(java.io.ObjectOutputStream s)
See readObject() and writeObject() in JComponent for more information about serialization in Swing.

        s.defaultWriteObject();
        if (getUIClassID().equals(uiClassID)) {
            byte count = JComponent.getWriteObjCounter(this);
            JComponent.setWriteObjCounter(this, --count);
            if (count == 0 && ui != null) {
                ui.installUI(this);
            }
        }