Example usage for Java javax.swing JButton fields, constructors, methods, implement or subclass
The text is from its open source code.
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. |
Component | add(Component comp) Appends the specified component to the end of this container. |
void | addActionListener(ActionListener l) Adds an ActionListener to the button. |
void | addAncestorListener(AncestorListener listener) Registers listener so that it will receive AncestorEvents when it or any of its ancestors move or are made visible or invisible. |
void | addChangeListener(ChangeListener l) Adds a ChangeListener to the button. |
void | addComponentListener(ComponentListener l) Adds the specified component listener to receive component events from this component. |
void | addFocusListener(FocusListener l) Adds the specified focus listener to receive focus events from this component when this component gains input focus. |
void | addItemListener(ItemListener l) Adds an ItemListener to the checkbox . |
void | addKeyListener(KeyListener l) Adds the specified key listener to receive key events from this component. |
void | addMouseListener(MouseListener l) Adds the specified mouse listener to receive mouse events from this component. |
void | addPropertyChangeListener(PropertyChangeListener listener) Adds a PropertyChangeListener to the listener list. |
void | applyComponentOrientation(ComponentOrientation o) Sets the ComponentOrientation property of this container and all components contained within it. |
void | doClick() Programmatically perform a "click". |
boolean | equals(Object obj) Indicates whether some other object is "equal to" this one. |
AccessibleContext | getAccessibleContext() Gets the AccessibleContext associated with this JButton . |
Action | getAction() Returns the currently set Action for this ActionEvent source, or null if no Action is set. |
String | getActionCommand() Returns the action command for this button. |
ActionListener | getActionForKeyStroke(KeyStroke aKeyStroke) Returns the object that will perform the action registered for a given keystroke. |
ActionListener[] | getActionListeners() Returns an array of all the ActionListener s added to this AbstractButton with addActionListener(). |
ActionMap | getActionMap() Returns the ActionMap used to determine what Action to fire for particular KeyStroke binding. |
Color | getBackground() Gets the background color of this component. |
Border | getBorder() Returns the border of this component or null if no border is currently set. |
Rectangle | getBounds() Gets the bounds of this component in the form of a Rectangle object. |
Object | getClientProperty(Object key) Returns the value of the property with the specified key. |
ComponentOrientation | getComponentOrientation() Retrieves the language-sensitive orientation that is to be used to order the elements or text within this component. |
Set | getFocusTraversalKeys(int id) Returns the Set of focus traversal keys for a given traversal operation for this Container. |
Font | getFont() Gets the font of this component. |
FontMetrics | getFontMetrics(Font font) Gets the FontMetrics for the specified Font . |
Color | getForeground() Gets the foreground color of this component. |
Graphics | getGraphics() Returns this component's graphics context, which lets you draw on a component. |
int | getHeight() Returns the current height of this component. |
Icon | getIcon() Returns the default icon. |
int | getIconTextGap() Returns the amount of space between the text and the icon displayed in this button. |
InputMap | getInputMap() Returns the InputMap that is used when the component has focus. |
InputMap | getInputMap(int condition) Returns the InputMap that is used during condition . |
Insets | getInsets() If a border has been set on this component, returns the border's insets; otherwise calls super.getInsets . |
Point | getLocation() Gets the location of this component in the form of a point specifying the component's top-left corner. |
Point | getLocationOnScreen() 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. |
Dimension | getMaximumSize() If the maximum size has been set to a non- null value just returns it. |
ButtonModel | getModel() Returns the model that this button represents. |
String | getName() Gets the name of the component. |
Container | getParent() Gets the parent of this component. |
Dimension | getPreferredSize() If the preferredSize has been set to a non-null value just returns it. |
Dimension | getSize() Returns the size of this component in the form of a Dimension object. |
String | getText() Returns the button's text. |
String | getToolTipText() Returns the tooltip string that has been set with setToolTipText . |
Container | getTopLevelAncestor() 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. |
ButtonUI | getUI() Returns the L&F object that renders this component. |
int | getWidth() Returns the current width of this component. |
int | getX() Returns the current x coordinate of the component's origin. |
int | hashCode() Returns a hash code value for the object. |
void | hide() |
boolean | isEnabled() Determines whether this component is enabled. |
boolean | isVisible() Determines whether this component should be visible when its parent is visible. |
void | putClientProperty(Object key, Object value) Adds an arbitrary key/value "client property" to this component. |
void | registerKeyboardAction(ActionListener anAction, KeyStroke aKeyStroke, int aCondition) This method is now obsolete, please use a combination of getActionMap() and getInputMap() for similar behavior. |
void | removeActionListener(ActionListener l) Removes an ActionListener from the button. |
void | repaint() Repaints this component. |
void | requestFocus() Requests that this Component gets the input focus. |
boolean | requestFocusInWindow() Requests that this Component gets the input focus. |
void | revalidate() Supports deferred automatic layout. |
void | setAction(Action a) Sets the Action . |
void | setActionCommand(String actionCommand) Sets the action command for this button. |
void | setActionMap(ActionMap am) Sets the ActionMap to am . |
void | setAlignmentX(float alignmentX) Sets the horizontal alignment. |
void | setAlignmentY(float alignmentY) Sets the vertical alignment. |
void | setBackground(Color bg) Sets the background color of this component. |
void | setBorder(Border border) Sets the border of this component. |
void | setBorderPainted(boolean b) Sets the borderPainted property. |
void | setBounds(int x, int y, int width, int height) Moves and resizes this component. |
void | setBounds(Rectangle r) Moves and resizes this component to conform to the new bounding rectangle r . |
void | setComponentPopupMenu(JPopupMenu popup) Sets the JPopupMenu for this JComponent . |
void | setContentAreaFilled(boolean b) Sets the contentAreaFilled property. |
void | setCursor(Cursor cursor) Sets the cursor image to the specified cursor. |
void | setDebugGraphicsOptions(int debugOptions) Enables or disables diagnostic information about every graphics operation performed within the component or one of its children. |
void | setDefaultCapable(boolean defaultCapable) Sets the defaultCapable property, which determines whether this button can be made the default button for its root pane. |
void | setDisabledIcon(Icon disabledIcon) Sets the disabled icon for the button. |
void | setEnabled(boolean b) Enables (or disables) the button. |
void | setFocusable(boolean focusable) Sets the focusable state of this Component to the specified value. |
void | setFocusPainted(boolean b) Sets the paintFocus property, which must be true for the focus state to be painted. |
void | setFocusTraversalKeys(int id, Set extends AWTKeyStroke> keystrokes) Sets the focus traversal keys for a given traversal operation for this Component. |
void | setFont(Font font) Sets the font for this component. |
void | setForeground(Color fg) Sets the foreground color of this component. |
void | setHideActionText(boolean hideActionText) Sets the hideActionText property, which determines whether the button displays text from the Action . |
void | setHorizontalAlignment(int alignment) Sets the horizontal alignment of the icon and text. |
void | setHorizontalTextPosition(int textPosition) Sets the horizontal position of the text relative to the icon. |
void | setIcon(Icon defaultIcon) Sets the button's default icon. |
void | setIconTextGap(int iconTextGap) If both the icon and text properties are set, this property defines the space between them. |
void | setInputMap(int condition, InputMap map) Sets the InputMap to use under the condition condition to map . |
void | setLayout(LayoutManager mgr) Sets the layout manager for this container, refer to java.awt.Container#setLayout(LayoutManager) for a complete description of this method. |
void | setLocation(int x, int y) Moves this component to a new location. |
void | setMargin(Insets m) Sets space for margin between the button's border and the label. |
void | setMaximumSize(Dimension maximumSize) Sets the maximum size of this component to a constant value. |
void | setMinimumSize(Dimension minimumSize) Sets the minimum size of this component to a constant value. |
void | setMnemonic(int mnemonic) Sets the keyboard mnemonic on the current model. |
void | setModel(ButtonModel newModel) Sets the model that this button represents. |
void | setMultiClickThreshhold(long threshhold) Sets the amount of time (in milliseconds) required between mouse press events for the button to generate the corresponding action events. |
void | setName(String name) Sets the name of the component to the specified string. |
void | setOpaque(boolean isOpaque) If true the component paints every pixel within its bounds. |
void | setPreferredSize(Dimension preferredSize) Sets the preferred size of this component. |
void | setPressedIcon(Icon pressedIcon) Sets the pressed icon for the button. |
void | setRequestFocusEnabled(boolean requestFocusEnabled) Provides a hint as to whether or not this JComponent should get focus. |
void | setRolloverEnabled(boolean b) Sets the rolloverEnabled property, which must be true for rollover effects to occur. |
void | setRolloverIcon(Icon rolloverIcon) Sets the rollover icon for the button. |
void | setRolloverSelectedIcon(Icon rolloverSelectedIcon) Sets the rollover selected icon for the button. |
void | setSelected(boolean b) Sets the state of the button. |
void | setSelectedIcon(Icon selectedIcon) Sets the selected icon for the button. |
void | setSize(int width, int height) Resizes this component so that it has width width and height height . |
void | setSize(Dimension d) Resizes this component so that it has width d.width and height d.height . |
void | setText(String text) Sets the button's text. |
void | setToolTipText(String text) Registers the text to display in a tool tip. |
void | setTransferHandler(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. |
void | setUI(ButtonUI ui) Sets the L&F object that renders this component. |
void | setVerticalAlignment(int alignment) Sets the vertical alignment of the icon and text. |
void | setVerticalTextPosition(int textPosition) Sets the vertical position of the text relative to the icon. |
void | setVisible(boolean aFlag) Makes the component visible or invisible. |