public class Button extends ButtonBase
A simple button control. The button control can contain text and/or a graphic. A button control has three different modes
ENTER
key presses when it has focus. When the default button does not have focus, and focus is on another Button
control, the ENTER key press will be received by the other, non-default Button. When focus is elsewhere in
the user interface, and not on any Button, the ENTER key press will be received by the default button, if
one is specified, and if no other node in the scene consumes it first.SPACE
key.When a button is pressed and released a ActionEvent
is sent.
Your application can perform some action based on this event by implementing an
javafx.event.EventHandler
to process the ActionEvent
. Buttons can also respond to
mouse events by implementing an javafx.event.EventHandler
to process the javafx.scene.input.MouseEvent
MnemonicParsing is enabled by default for Button.
Example:
Button button = new Button("Click Me");
Type | Property and Description |
---|---|
BooleanProperty |
cancelButton
A Cancel Button is the button that receives
a keyboard VK_ESC press, if no other node in the scene consumes it.
|
BooleanProperty |
defaultButton
A default Button is the button that receives
a keyboard VK_ENTER press, if no other node in the scene consumes it.
|
armedProperty, onActionProperty
alignmentProperty, contentDisplayProperty, ellipsisStringProperty, fontProperty, graphicProperty, graphicTextGapProperty, labelPaddingProperty, lineSpacingProperty, mnemonicParsingProperty, textAlignmentProperty, textFillProperty, textOverrunProperty, textProperty, underlineProperty, wrapTextProperty
contextMenuProperty, skinClassNameProperty, skinProperty, tooltipProperty
Modifier and Type | Field and Description |
---|---|
private BooleanProperty |
cancelButton
A Cancel Button is the button that receives
a keyboard VK_ESC press, if no other node in the scene consumes it.
|
private static java.lang.String |
DEFAULT_STYLE_CLASS
Initialize the style class to 'button'.
|
private BooleanProperty |
defaultButton
A default Button is the button that receives
a keyboard VK_ENTER press, if no other node in the scene consumes it.
|
private static PseudoClass |
PSEUDO_CLASS_CANCEL |
private static PseudoClass |
PSEUDO_CLASS_DEFAULT |
Constructor and Description |
---|
Button()
Creates a button with an empty string for its label.
|
Button(java.lang.String text)
Creates a button with the specified text as its label.
|
Button(java.lang.String text,
Node graphic)
Creates a button with the specified text and icon for its label.
|
Modifier and Type | Method and Description |
---|---|
BooleanProperty |
cancelButtonProperty()
A Cancel Button is the button that receives
a keyboard VK_ESC press, if no other node in the scene consumes it.
|
protected Skin<?> |
createDefaultSkin()
Create a new instance of the default skin for this control.
|
BooleanProperty |
defaultButtonProperty()
A default Button is the button that receives
a keyboard VK_ENTER press, if no other node in the scene consumes it.
|
void |
fire()
Invoked when a user gesture indicates that an event for this
ButtonBase should occur. |
private void |
initialize() |
boolean |
isCancelButton()
Gets the value of the property cancelButton.
|
boolean |
isDefaultButton()
Gets the value of the property defaultButton.
|
void |
setCancelButton(boolean value)
Sets the value of the property cancelButton.
|
void |
setDefaultButton(boolean value)
Sets the value of the property defaultButton.
|
arm, armedProperty, disarm, executeAccessibleAction, getOnAction, isArmed, onActionProperty, setOnAction
alignmentProperty, contentDisplayProperty, ellipsisStringProperty, fontProperty, getAlignment, getClassCssMetaData, getContentBias, getContentDisplay, getControlCssMetaData, getEllipsisString, getFont, getGraphic, getGraphicTextGap, getInitialAlignment, getLabelPadding, getLineSpacing, getText, getTextAlignment, getTextFill, getTextOverrun, graphicProperty, graphicTextGapProperty, isMnemonicParsing, isUnderline, isWrapText, labelPaddingProperty, lineSpacingProperty, mnemonicParsingProperty, setAlignment, setContentDisplay, setEllipsisString, setFont, setGraphic, setGraphicTextGap, setLineSpacing, setMnemonicParsing, setText, setTextAlignment, setTextFill, setTextOverrun, setUnderline, setWrapText, textAlignmentProperty, textFillProperty, textOverrunProperty, textProperty, toString, underlineProperty, wrapTextProperty
computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, contextMenuProperty, getBaselineOffset, getContextMenu, getControlChildren, getCssMetaData, getInitialFocusTraversable, getSkin, getTooltip, isResizable, layoutChildren, loadSkinClass, queryAccessibleAttribute, setContextMenu, setSkin, setTooltip, skinClassNameProperty, skinProperty, tooltipProperty
public final BooleanProperty defaultButtonProperty
isDefaultButton()
,
setDefaultButton(boolean)
public final BooleanProperty cancelButtonProperty
isCancelButton()
,
setCancelButton(boolean)
private BooleanProperty defaultButton
private BooleanProperty cancelButton
private static final java.lang.String DEFAULT_STYLE_CLASS
private static final PseudoClass PSEUDO_CLASS_DEFAULT
private static final PseudoClass PSEUDO_CLASS_CANCEL
public Button()
public Button(java.lang.String text)
text
- A text string for its label.public Button(java.lang.String text, Node graphic)
text
- A text string for its label.graphic
- the icon for its label.private void initialize()
public final void setDefaultButton(boolean value)
public final boolean isDefaultButton()
public final BooleanProperty defaultButtonProperty()
isDefaultButton()
,
setDefaultButton(boolean)
public final void setCancelButton(boolean value)
public final boolean isCancelButton()
public final BooleanProperty cancelButtonProperty()
isCancelButton()
,
setCancelButton(boolean)
public void fire()
ButtonBase
should occur.
If invoked, this method will be executed regardless of the status of
ButtonBase.arm()
.
fire
in class ButtonBase
protected Skin<?> createDefaultSkin()
-fx-skin
or set explicitly in a sub-class with setSkin(...)
.createDefaultSkin
in class Control