javax.swing

Class JButton

public class JButton extends AbstractButton implements Accessible

A general purpose push button. JButtons can display a label, an {@link Icon} or both.
Nested Class Summary
protected classJButton.AccessibleJButton
Accessibility support for JButtons.
Constructor Summary
JButton()
Creates a new button with an empty string for the button text and no icon.
JButton(Action a)
Creates a new button from the specified action.
JButton(Icon icon)
Creates a new button with the specified icon (and an empty string for the button text).
JButton(String text)
Creates a new button with the specified text and no icon.
JButton(String text, Icon icon)
Creates a new button with the specified text and icon.
Method Summary
protected voidconfigurePropertiesFromAction(Action a)
AccessibleContextgetAccessibleContext()
Returns the object that provides accessibility features for this JButton component.
StringgetUIClassID()
Returns the suffix ("ButtonUI" in this case) used to determine the class name for a UI delegate that can provide the look and feel for a JButton.
booleanisDefaultButton()
Returns true if this button is the default button in its JRootPane.
booleanisDefaultCapable()
Returns true if this button can act as the default button.
protected StringparamString()
Returns an implementation-dependent string describing the attributes of this JButton.
voidremoveNotify()
Overrides JComponent.removeNotify to check if this button is currently set as the default button on the RootPane, and if so, sets the RootPane's default button to null to ensure the RootPane doesn't hold onto an invalid button reference.
voidsetDefaultCapable(boolean defaultCapable)
Sets the defaultCapable property which indicates if this button may become the default button in its JRootPane.
voidupdateUI()
Sets this button's UI delegate to the default (obtained from the {@link UIManager}) for the current look and feel.

Constructor Detail

JButton

public JButton()
Creates a new button with an empty string for the button text and no icon.

JButton

public JButton(Action a)
Creates a new button from the specified action.

Parameters: a the action (null permitted).

See Also: setAction

JButton

public JButton(Icon icon)
Creates a new button with the specified icon (and an empty string for the button text).

Parameters: icon the icon (null permitted).

JButton

public JButton(String text)
Creates a new button with the specified text and no icon.

Parameters: text the button text (null permitted, will be substituted by an empty string).

JButton

public JButton(String text, Icon icon)
Creates a new button with the specified text and icon.

Parameters: text the button text (null permitted, will be substituted by an empty string). icon the icon (null permitted).

Method Detail

configurePropertiesFromAction

protected void configurePropertiesFromAction(Action a)

getAccessibleContext

public AccessibleContext getAccessibleContext()
Returns the object that provides accessibility features for this JButton component.

Returns: The accessible context (an instance of {@link AccessibleJButton}).

getUIClassID

public String getUIClassID()
Returns the suffix ("ButtonUI" in this case) used to determine the class name for a UI delegate that can provide the look and feel for a JButton.

Returns: "ButtonUI".

isDefaultButton

public boolean isDefaultButton()
Returns true if this button is the default button in its JRootPane. The default button gets automatically activated when the user presses ENTER (or whatever key this is bound to in the current Look and Feel).

Returns: true if this button is the default button in its JRootPane

See Also: isDefaultCapable JButton getDefaultButton setDefaultButton

isDefaultCapable

public boolean isDefaultCapable()
Returns true if this button can act as the default button. This is true by default.

Returns: true if this button can act as the default button

See Also: JButton isDefaultButton getDefaultButton setDefaultButton

paramString

protected String paramString()
Returns an implementation-dependent string describing the attributes of this JButton.

Returns: A string describing the attributes of this JButton (never null).

removeNotify

public void removeNotify()
Overrides JComponent.removeNotify to check if this button is currently set as the default button on the RootPane, and if so, sets the RootPane's default button to null to ensure the RootPane doesn't hold onto an invalid button reference.

setDefaultCapable

public void setDefaultCapable(boolean defaultCapable)
Sets the defaultCapable property which indicates if this button may become the default button in its JRootPane.

Parameters: defaultCapable true if this button can become the default button in its JRootPane, false otherwise

See Also: JButton isDefaultButton getDefaultButton setDefaultButton

updateUI

public void updateUI()
Sets this button's UI delegate to the default (obtained from the {@link UIManager}) for the current look and feel.