Constructors Summary |
---|
public JButton()Creates a button with no set text or icon.
this(null, null);
|
public JButton(Icon icon)Creates a button with an icon.
this(null, icon);
|
public JButton(String text)Creates a button with text.
this(text, null);
|
public JButton(Action a)Creates a button where properties are taken from the
Action supplied.
this();
setAction(a);
|
public JButton(String text, Icon icon)Creates a button with initial text and an icon.
// Create the model
setModel(new DefaultButtonModel());
// initialize
init(text, icon);
|
Methods Summary |
---|
public javax.accessibility.AccessibleContext | getAccessibleContext()Gets the AccessibleContext associated with this
JButton . For JButton s,
the AccessibleContext takes the form of an
AccessibleJButton .
A new AccessibleJButton instance is created if necessary.
if (accessibleContext == null) {
accessibleContext = new AccessibleJButton();
}
return accessibleContext;
|
public java.lang.String | getUIClassID()Returns a string that specifies the name of the L&F class
that renders this component.
return uiClassID;
|
public boolean | isDefaultButton()Gets the value of the defaultButton property,
which if true means that this button is the current
default button for its JRootPane .
Most look and feels render the default button
differently, and may potentially provide bindings
to access the default button.
JRootPane root = SwingUtilities.getRootPane(this);
if (root != null) {
return root.getDefaultButton() == this;
}
return false;
|
public boolean | isDefaultCapable()Gets the value of the defaultCapable property.
return defaultCapable;
|
protected java.lang.String | paramString()Returns a string representation of this JButton .
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 .
String defaultCapableString = (defaultCapable ? "true" : "false");
return super.paramString() +
",defaultCapable=" + defaultCapableString;
|
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.
JRootPane root = SwingUtilities.getRootPane(this);
if (root != null && root.getDefaultButton() == this) {
root.setDefaultButton(null);
}
super.removeNotify();
|
public void | setDefaultCapable(boolean defaultCapable)Sets the defaultCapable property,
which determines whether this button can be
made the default button for its root pane.
The default value of the defaultCapable
property is true unless otherwise
specified by the look and feel.
boolean oldDefaultCapable = this.defaultCapable;
this.defaultCapable = defaultCapable;
firePropertyChange("defaultCapable", oldDefaultCapable, defaultCapable);
|
public void | updateUI()Resets the UI property to a value from the current look and
feel.
setUI((ButtonUI)UIManager.getUI(this));
|
private void | writeObject(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);
}
}
|