javax.swing
public class JButton extends AbstractButton implements Accessible
JButton
s can display a label,
an Icon
or both.Modifier and Type | Class and Description |
---|---|
protected class |
JButton.AccessibleJButton
Accessibility support for JButtons.
|
AbstractButton.AccessibleAbstractButton, AbstractButton.ButtonChangeListener
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
actionListener, BORDER_PAINTED_CHANGED_PROPERTY, changeEvent, changeListener, CONTENT_AREA_FILLED_CHANGED_PROPERTY, DISABLED_ICON_CHANGED_PROPERTY, DISABLED_SELECTED_ICON_CHANGED_PROPERTY, FOCUS_PAINTED_CHANGED_PROPERTY, HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY, HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY, ICON_CHANGED_PROPERTY, itemListener, MARGIN_CHANGED_PROPERTY, MNEMONIC_CHANGED_PROPERTY, model, MODEL_CHANGED_PROPERTY, PRESSED_ICON_CHANGED_PROPERTY, ROLLOVER_ENABLED_CHANGED_PROPERTY, ROLLOVER_ICON_CHANGED_PROPERTY, ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY, SELECTED_ICON_CHANGED_PROPERTY, TEXT_CHANGED_PROPERTY, VERTICAL_ALIGNMENT_CHANGED_PROPERTY, VERTICAL_TEXT_POSITION_CHANGED_PROPERTY
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
protected void |
configurePropertiesFromAction(Action a)
Configure various properties of the button by reading properties
of an
Action . |
AccessibleContext |
getAccessibleContext()
Returns the object that provides accessibility features for this
JButton component. |
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 . |
boolean |
isDefaultButton()
Returns
true if this button is the default button in
its JRootPane . |
boolean |
isDefaultCapable()
Returns
true if this button can act as the default button. |
protected String |
paramString()
Returns an implementation-dependent string describing the attributes of
this
JButton . |
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.
|
void |
setDefaultCapable(boolean defaultCapable)
Sets the
defaultCapable property which indicates if
this button may become the default button in its JRootPane . |
void |
updateUI()
Sets this button's UI delegate to the default (obtained from the
UIManager ) for the current look and feel. |
addActionListener, addChangeListener, addImpl, addItemListener, checkHorizontalKey, checkVerticalKey, createActionListener, createActionPropertyChangeListener, createChangeListener, createItemListener, doClick, doClick, fireActionPerformed, fireItemStateChanged, fireStateChanged, getAction, getActionCommand, getActionListeners, getChangeListeners, getDisabledIcon, getDisabledSelectedIcon, getDisplayedMnemonicIndex, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getItemListeners, getLabel, getMargin, getMnemonic, getModel, getMultiClickThreshhold, getPressedIcon, getRolloverIcon, getRolloverSelectedIcon, getSelectedIcon, getSelectedObjects, getText, getUI, getVerticalAlignment, getVerticalTextPosition, imageUpdate, init, isBorderPainted, isContentAreaFilled, isFocusPainted, isRolloverEnabled, isSelected, paintBorder, removeActionListener, removeChangeListener, removeItemListener, setAction, setActionCommand, setBorderPainted, setContentAreaFilled, setDisabledIcon, setDisabledSelectedIcon, setDisplayedMnemonicIndex, setEnabled, setFocusPainted, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabel, setLayout, setMargin, setMnemonic, setMnemonic, setModel, setMultiClickThreshhold, setPressedIcon, setRolloverEnabled, setRolloverIcon, setRolloverSelectedIcon, setSelected, setSelectedIcon, setText, setUI, setVerticalAlignment, setVerticalTextPosition
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setNextFocusableComponent, setOpaque, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, transferFocusDownCycle, validate, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public JButton()
public JButton(Action a)
a
- the action (null
permitted).AbstractButton.setAction(Action)
public JButton(Icon icon)
icon
- the icon (null
permitted).public JButton(String text)
text
- the button text (null
permitted, will be
substituted by an empty string).protected void configurePropertiesFromAction(Action a)
AbstractButton
Action
. The mapping of properties is as follows:
Action keyed property | AbstractButton property |
---|---|
NAME | text |
SMALL_ICON | icon |
SHORT_DESCRIPTION | toolTipText |
MNEMONIC_KEY | mnemonic |
ACTION_COMMAND_KEY | actionCommand |
In addition, this method always sets the button's "enabled" property to the value of the Action's "enabled" property.
If the provided Action is null
, the text, icon, and
toolTipText properties of the button are set to null
, and
the "enabled" property is set to true
; the mnemonic and
actionCommand properties are unchanged.
configurePropertiesFromAction
in class AbstractButton
a
- An Action to configure the button frompublic AccessibleContext getAccessibleContext()
JButton
component.getAccessibleContext
in interface Accessible
getAccessibleContext
in class JComponent
JButton.AccessibleJButton
).public String getUIClassID()
"ButtonUI"
in this case) used to
determine the class name for a UI delegate that can provide the look and
feel for a JButton
.getUIClassID
in class JComponent
"ButtonUI"
.JComponent.setUI(javax.swing.plaf.ComponentUI)
,
JComponent.updateUI()
public boolean isDefaultButton()
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).true
if this button is the default button in
its JRootPane
isDefaultCapable()
,
setDefaultCapable(boolean)
,
JRootPane.getDefaultButton()
,
JRootPane.setDefaultButton(JButton)
public boolean isDefaultCapable()
true
if this button can act as the default button.
This is true
by default.true
if this button can act as the default buttonsetDefaultCapable(boolean)
,
isDefaultButton()
,
JRootPane.getDefaultButton()
,
JRootPane.setDefaultButton(JButton)
protected String paramString()
JButton
.paramString
in class AbstractButton
JButton
(never null
).public void removeNotify()
removeNotify
in class JComponent
Component.isDisplayable()
,
Component.addNotify()
public void setDefaultCapable(boolean defaultCapable)
defaultCapable
property which indicates if
this button may become the default button in its JRootPane
.defaultCapable
- true
if this button can become the
default button in its JRootPane, false
otherwisesetDefaultCapable(boolean)
,
isDefaultButton()
,
JRootPane.getDefaultButton()
,
JRootPane.setDefaultButton(JButton)
public void updateUI()
UIManager
) for the current look and feel.updateUI
in class AbstractButton