Java javax.swing JButton fields, constructors, methods, implement or subclass

Example usage for Java javax.swing JButton fields, constructors, methods, implement or subclass

Introduction

In this page you can find the methods, fields and constructors for javax.swing JButton.

The text is from its open source code.

Subclass

javax.swing.JButton has subclasses.
Click this link to see all its subclasses.

Constructor

JButton()
Creates a button with no set text or icon.
JButton(Icon icon)
Creates a button with an icon.
JButton(String text)
Creates a button with text.
JButton(Action a)
Creates a button where properties are taken from the Action supplied.
JButton(String text, Icon icon)
Creates a button with initial text and an icon.

Method

Componentadd(Component comp)
Appends the specified component to the end of this container.
voidaddActionListener(ActionListener l)
Adds an ActionListener to the button.
voidaddAncestorListener(AncestorListener listener)
Registers listener so that it will receive AncestorEvents when it or any of its ancestors move or are made visible or invisible.
voidaddChangeListener(ChangeListener l)
Adds a ChangeListener to the button.
voidaddComponentListener(ComponentListener l)
Adds the specified component listener to receive component events from this component.
voidaddFocusListener(FocusListener l)
Adds the specified focus listener to receive focus events from this component when this component gains input focus.
voidaddItemListener(ItemListener l)
Adds an ItemListener to the checkbox.
voidaddKeyListener(KeyListener l)
Adds the specified key listener to receive key events from this component.
voidaddMouseListener(MouseListener l)
Adds the specified mouse listener to receive mouse events from this component.
voidaddPropertyChangeListener(PropertyChangeListener listener)
Adds a PropertyChangeListener to the listener list.
voidapplyComponentOrientation(ComponentOrientation o)
Sets the ComponentOrientation property of this container and all components contained within it.
voiddoClick()
Programmatically perform a "click".
booleanequals(Object obj)
Indicates whether some other object is "equal to" this one.
AccessibleContextgetAccessibleContext()
Gets the AccessibleContext associated with this JButton.
ActiongetAction()
Returns the currently set Action for this ActionEvent source, or null if no Action is set.
StringgetActionCommand()
Returns the action command for this button.
ActionListenergetActionForKeyStroke(KeyStroke aKeyStroke)
Returns the object that will perform the action registered for a given keystroke.
ActionListener[]getActionListeners()
Returns an array of all the ActionListeners added to this AbstractButton with addActionListener().
ActionMapgetActionMap()
Returns the ActionMap used to determine what Action to fire for particular KeyStroke binding.
ColorgetBackground()
Gets the background color of this component.
BordergetBorder()
Returns the border of this component or null if no border is currently set.
RectanglegetBounds()
Gets the bounds of this component in the form of a Rectangle object.
ObjectgetClientProperty(Object key)
Returns the value of the property with the specified key.
ComponentOrientationgetComponentOrientation()
Retrieves the language-sensitive orientation that is to be used to order the elements or text within this component.
SetgetFocusTraversalKeys(int id)
Returns the Set of focus traversal keys for a given traversal operation for this Container.
FontgetFont()
Gets the font of this component.
FontMetricsgetFontMetrics(Font font)
Gets the FontMetrics for the specified Font.
ColorgetForeground()
Gets the foreground color of this component.
GraphicsgetGraphics()
Returns this component's graphics context, which lets you draw on a component.
intgetHeight()
Returns the current height of this component.
IcongetIcon()
Returns the default icon.
intgetIconTextGap()
Returns the amount of space between the text and the icon displayed in this button.
InputMapgetInputMap()
Returns the InputMap that is used when the component has focus.
InputMapgetInputMap(int condition)
Returns the InputMap that is used during condition.
InsetsgetInsets()
If a border has been set on this component, returns the border's insets; otherwise calls super.getInsets.
PointgetLocation()
Gets the location of this component in the form of a point specifying the component's top-left corner.
PointgetLocationOnScreen()
Gets the location of this component in the form of a point specifying the component's top-left corner in the screen's coordinate space.
DimensiongetMaximumSize()
If the maximum size has been set to a non-null value just returns it.
ButtonModelgetModel()
Returns the model that this button represents.
StringgetName()
Gets the name of the component.
ContainergetParent()
Gets the parent of this component.
DimensiongetPreferredSize()
If the preferredSize has been set to a non-null value just returns it.
DimensiongetSize()
Returns the size of this component in the form of a Dimension object.
StringgetText()
Returns the button's text.
StringgetToolTipText()
Returns the tooltip string that has been set with setToolTipText.
ContainergetTopLevelAncestor()
Returns the top-level ancestor of this component (either the containing Window or Applet), or null if this component has not been added to any container.
ButtonUIgetUI()
Returns the L&F object that renders this component.
intgetWidth()
Returns the current width of this component.
intgetX()
Returns the current x coordinate of the component's origin.
inthashCode()
Returns a hash code value for the object.
voidhide()
booleanisEnabled()
Determines whether this component is enabled.
booleanisVisible()
Determines whether this component should be visible when its parent is visible.
voidputClientProperty(Object key, Object value)
Adds an arbitrary key/value "client property" to this component.
voidregisterKeyboardAction(ActionListener anAction, KeyStroke aKeyStroke, int aCondition)
This method is now obsolete, please use a combination of getActionMap() and getInputMap() for similar behavior.
voidremoveActionListener(ActionListener l)
Removes an ActionListener from the button.
voidrepaint()
Repaints this component.
voidrequestFocus()
Requests that this Component gets the input focus.
booleanrequestFocusInWindow()
Requests that this Component gets the input focus.
voidrevalidate()
Supports deferred automatic layout.
voidsetAction(Action a)
Sets the Action.
voidsetActionCommand(String actionCommand)
Sets the action command for this button.
voidsetActionMap(ActionMap am)
Sets the ActionMap to am.
voidsetAlignmentX(float alignmentX)
Sets the horizontal alignment.
voidsetAlignmentY(float alignmentY)
Sets the vertical alignment.
voidsetBackground(Color bg)
Sets the background color of this component.
voidsetBorder(Border border)
Sets the border of this component.
voidsetBorderPainted(boolean b)
Sets the borderPainted property.
voidsetBounds(int x, int y, int width, int height)
Moves and resizes this component.
voidsetBounds(Rectangle r)
Moves and resizes this component to conform to the new bounding rectangle r .
voidsetComponentPopupMenu(JPopupMenu popup)
Sets the JPopupMenu for this JComponent.
voidsetContentAreaFilled(boolean b)
Sets the contentAreaFilled property.
voidsetCursor(Cursor cursor)
Sets the cursor image to the specified cursor.
voidsetDebugGraphicsOptions(int debugOptions)
Enables or disables diagnostic information about every graphics operation performed within the component or one of its children.
voidsetDefaultCapable(boolean defaultCapable)
Sets the defaultCapable property, which determines whether this button can be made the default button for its root pane.
voidsetDisabledIcon(Icon disabledIcon)
Sets the disabled icon for the button.
voidsetEnabled(boolean b)
Enables (or disables) the button.
voidsetFocusable(boolean focusable)
Sets the focusable state of this Component to the specified value.
voidsetFocusPainted(boolean b)
Sets the paintFocus property, which must be true for the focus state to be painted.
voidsetFocusTraversalKeys(int id, Set keystrokes)
Sets the focus traversal keys for a given traversal operation for this Component.
voidsetFont(Font font)
Sets the font for this component.
voidsetForeground(Color fg)
Sets the foreground color of this component.
voidsetHideActionText(boolean hideActionText)
Sets the hideActionText property, which determines whether the button displays text from the Action.
voidsetHorizontalAlignment(int alignment)
Sets the horizontal alignment of the icon and text.
voidsetHorizontalTextPosition(int textPosition)
Sets the horizontal position of the text relative to the icon.
voidsetIcon(Icon defaultIcon)
Sets the button's default icon.
voidsetIconTextGap(int iconTextGap)
If both the icon and text properties are set, this property defines the space between them.
voidsetInputMap(int condition, InputMap map)
Sets the InputMap to use under the condition condition to map.
voidsetLayout(LayoutManager mgr)
Sets the layout manager for this container, refer to java.awt.Container#setLayout(LayoutManager) for a complete description of this method.
voidsetLocation(int x, int y)
Moves this component to a new location.
voidsetMargin(Insets m)
Sets space for margin between the button's border and the label.
voidsetMaximumSize(Dimension maximumSize)
Sets the maximum size of this component to a constant value.
voidsetMinimumSize(Dimension minimumSize)
Sets the minimum size of this component to a constant value.
voidsetMnemonic(int mnemonic)
Sets the keyboard mnemonic on the current model.
voidsetModel(ButtonModel newModel)
Sets the model that this button represents.
voidsetMultiClickThreshhold(long threshhold)
Sets the amount of time (in milliseconds) required between mouse press events for the button to generate the corresponding action events.
voidsetName(String name)
Sets the name of the component to the specified string.
voidsetOpaque(boolean isOpaque)
If true the component paints every pixel within its bounds.
voidsetPreferredSize(Dimension preferredSize)
Sets the preferred size of this component.
voidsetPressedIcon(Icon pressedIcon)
Sets the pressed icon for the button.
voidsetRequestFocusEnabled(boolean requestFocusEnabled)
Provides a hint as to whether or not this JComponent should get focus.
voidsetRolloverEnabled(boolean b)
Sets the rolloverEnabled property, which must be true for rollover effects to occur.
voidsetRolloverIcon(Icon rolloverIcon)
Sets the rollover icon for the button.
voidsetRolloverSelectedIcon(Icon rolloverSelectedIcon)
Sets the rollover selected icon for the button.
voidsetSelected(boolean b)
Sets the state of the button.
voidsetSelectedIcon(Icon selectedIcon)
Sets the selected icon for the button.
voidsetSize(int width, int height)
Resizes this component so that it has width width and height height .
voidsetSize(Dimension d)
Resizes this component so that it has width d.width and height d.height .
voidsetText(String text)
Sets the button's text.
voidsetToolTipText(String text)
Registers the text to display in a tool tip.
voidsetTransferHandler(TransferHandler newHandler)
Sets the TransferHandler , which provides support for transfer of data into and out of this component via cut/copy/paste and drag and drop.
voidsetUI(ButtonUI ui)
Sets the L&F object that renders this component.
voidsetVerticalAlignment(int alignment)
Sets the vertical alignment of the icon and text.
voidsetVerticalTextPosition(int textPosition)
Sets the vertical position of the text relative to the icon.
voidsetVisible(boolean aFlag)
Makes the component visible or invisible.