Class DialogPane
- All Implemented Interfaces:
Styleable
,EventTarget
Dialog
instance. In this role, the DialogPane is responsible for the
placement of headers
, graphics
,
content
, and buttons
.
The default implementation of DialogPane (that is, the DialogPane class itself)
handles the layout via the normal Parent.layoutChildren()
method. This
method may be overridden by subclasses wishing to handle the layout in an
alternative fashion).
In addition to the header
and
content
properties, there exists
header text
and
content text
properties. The way the *Text
properties work is that they are a lower precedence compared to the Node
properties, but they are far more convenient for developers in the common case,
as it is likely the case that a developer more often than not simply wants to
set a string value into the header or content areas of the DialogPane.
It is important to understand the implications of setting non-null values
in the header
and headerText
properties. The key points are as follows:
- The
header
property takes precedence over theheaderText
property, so if both are set to non-null values,header
will be used andheaderText
will be ignored. - If
headerText
is set to a non-null value, and agraphic
has also been set, the default position for the graphic shifts from being located to the left of the content area to being to the right of the header text. - If
header
is set to a non-null value, and agraphic
has also been set, the graphic is removed from its default position (to the left of the content area), and is not placed to the right of the custom header node. If the graphic is desired, it should be manually added in to the layout of the custom header node manually.
DialogPane operates on the concept of ButtonType
. A ButtonType is
a descriptor of a single button that should be represented visually in the
DialogPane. Developers who create a DialogPane therefore must specify the
button types that they want to display, and this is done via the
getButtonTypes()
method, which returns a modifiable
ObservableList
, which users can add to and remove from as desired.
The ButtonType
class defines a number of pre-defined button types,
such as ButtonType.OK
and ButtonType.CANCEL
. Many users of the
JavaFX dialogs API will find that these pre-defined button types meet their
needs, particularly due to their built-in support for
default
and
cancel
buttons, as well as the benefit of
the strings being translated into all languages which JavaFX is translated to.
For users that want to define their own ButtonType
(most commonly to
define a button with custom text), they may do so via the constructors available
on the ButtonType
class.
Developers will quickly find that the amount of configurability offered
via the ButtonType
class is minimal. This is intentional, but does not
mean that developers can not modify the buttons created by the ButtonType
that have been specified. To do this, developers simply call the
lookupButton(ButtonType)
method with the ButtonType (assuming it has
already been set in the getButtonTypes()
list. The returned Node is
typically of type Button
, but this depends on if the
createButton(ButtonType)
method has been overridden.
The DialogPane class offers a few methods that can be overridden by subclasses, to more easily enable custom functionality. These methods include the following:
These methods are documented, so please take note of the expectations placed on any developer who wishes to override these methods with their own functionality.
- Since:
- JavaFX 8u40
- See Also:
-
Property Summary
TypePropertyDescriptionfinal ObjectProperty
<Node> Property representing the content area of the dialog.final StringProperty
A property representing the content text for the dialog pane.final ObjectProperty
<Node> A property that represents the dialog expandable content area.final BooleanProperty
Represents whether the dialogPane is expanded.final ObjectProperty
<Node> The dialog graphic, presented either in the header, if one is showing, or to the left of thecontent
.final ObjectProperty
<Node> Property representing the header area of the dialog pane.final StringProperty
A property representing the header text for the dialog pane.Properties declared in class javafx.scene.layout.Region
background, border, cacheShape, centerShape, height, insets, maxHeight, maxWidth, minHeight, minWidth, opaqueInsets, padding, prefHeight, prefWidth, scaleShape, shape, snapToPixel, width
Properties declared in class javafx.scene.Parent
needsLayout
Properties declared in class javafx.scene.Node
accessibleHelp, accessibleRoleDescription, accessibleRole, accessibleText, blendMode, boundsInLocal, boundsInParent, cacheHint, cache, clip, cursor, depthTest, disabled, disable, effectiveNodeOrientation, effect, eventDispatcher, focused, focusTraversable, focusVisible, focusWithin, hover, id, inputMethodRequests, layoutBounds, layoutX, layoutY, localToParentTransform, localToSceneTransform, managed, mouseTransparent, nodeOrientation, onContextMenuRequested, onDragDetected, onDragDone, onDragDropped, onDragEntered, onDragExited, onDragOver, onInputMethodTextChanged, onKeyPressed, onKeyReleased, onKeyTyped, onMouseClicked, onMouseDragEntered, onMouseDragExited, onMouseDragged, onMouseDragOver, onMouseDragReleased, onMouseEntered, onMouseExited, onMouseMoved, onMousePressed, onMouseReleased, onRotate, onRotationFinished, onRotationStarted, onScrollFinished, onScroll, onScrollStarted, onSwipeDown, onSwipeLeft, onSwipeRight, onSwipeUp, onTouchMoved, onTouchPressed, onTouchReleased, onTouchStationary, onZoomFinished, onZoom, onZoomStarted, opacity, parent, pickOnBounds, pressed, rotate, rotationAxis, scaleX, scaleY, scaleZ, scene, style, translateX, translateY, translateZ, viewOrder, visible
-
Field Summary
Fields declared in class javafx.scene.layout.Region
USE_COMPUTED_SIZE, USE_PREF_SIZE
Fields declared in class javafx.scene.Node
BASELINE_OFFSET_SAME_AS_HEIGHT
-
Constructor Summary
ConstructorDescriptionCreates a new DialogPane instance with a style class of 'dialog-pane'. -
Method Summary
Modifier and TypeMethodDescriptionfinal ObjectProperty
<Node> Property representing the content area of the dialog.final StringProperty
A property representing the content text for the dialog pane.protected Node
createButton
(ButtonType buttonType) This method can be overridden by subclasses to create a custom button that will subsequently inserted into the DialogPane button area (created via thecreateButtonBar()
method, but mostly commonly it is an instance ofButtonBar
.protected Node
This method can be overridden by subclasses to provide the button bar.protected Node
This method can be overridden by subclasses to create a custom details button.final ObjectProperty
<Node> A property that represents the dialog expandable content area.final BooleanProperty
Represents whether the dialogPane is expanded.final ObservableList
<ButtonType> Observable list of button types used for the dialog button bar area (created via thecreateButtonBar()
method).static List
<CssMetaData<? extends Styleable, ?>> Gets theCssMetaData
associated with this class, which may include theCssMetaData
of its superclasses.final Node
Returns the dialog content as a Node (even if it was set as a String usingsetContentText(String)
- this was simply transformed into aNode
(most probably aLabel
).final String
Returns the currently-set content text for this DialogPane.final Node
Returns the dialog expandable content node, if one is set, or null otherwise.final Node
Gets the value of thegraphic
property.final Node
Node which acts as the dialog pane header.final String
Returns the currently-set header text for this DialogPane.final ObjectProperty
<Node> The dialog graphic, presented either in the header, if one is showing, or to the left of thecontent
.final ObjectProperty
<Node> Property representing the header area of the dialog pane.final StringProperty
A property representing the header text for the dialog pane.final boolean
Returns whether or not the dialogPane is expanded.final Node
lookupButton
(ButtonType buttonType) This method provides a way in which developers may retrieve the actual Node for a givenButtonType
(assuming it is part of thebutton types
list).final void
setContent
(Node content) Assign dialog content.final void
setContentText
(String contentText) Sets the string to show in the dialog content area.final void
setExpandableContent
(Node content) Sets the dialog expandable content node, or null if no expandable content needs to be shown.final void
setExpanded
(boolean value) Sets whether the dialogPane is expanded.final void
setGraphic
(Node graphic) Sets the dialog graphic, which will be displayed either in the header, if one is showing, or to the left of thecontent
.final void
Assigns the dialog pane header.final void
setHeaderText
(String headerText) Sets the string to show in the dialog header area.Methods declared in class javafx.scene.layout.Pane
getChildren
Methods declared in class javafx.scene.layout.Region
backgroundProperty, borderProperty, cacheShapeProperty, centerShapeProperty, computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, getBackground, getBorder, getCssMetaData, getHeight, getInsets, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getOpaqueInsets, getPadding, getPrefHeight, getPrefWidth, getShape, getUserAgentStylesheet, getWidth, heightProperty, insetsProperty, isCacheShape, isCenterShape, isResizable, isScaleShape, isSnapToPixel, layoutInArea, layoutInArea, layoutInArea, layoutInArea, maxHeight, maxHeightProperty, maxWidth, maxWidthProperty, minHeight, minHeightProperty, minWidth, minWidthProperty, opaqueInsetsProperty, paddingProperty, positionInArea, positionInArea, prefHeight, prefHeightProperty, prefWidth, prefWidthProperty, resize, scaleShapeProperty, setBackground, setBorder, setCacheShape, setCenterShape, setHeight, setMaxHeight, setMaxSize, setMaxWidth, setMinHeight, setMinSize, setMinWidth, setOpaqueInsets, setPadding, setPrefHeight, setPrefSize, setPrefWidth, setScaleShape, setShape, setSnapToPixel, setWidth, shapeProperty, snappedBottomInset, snappedLeftInset, snappedRightInset, snappedTopInset, snapPosition, snapPositionX, snapPositionY, snapSize, snapSizeX, snapSizeY, snapSpace, snapSpaceX, snapSpaceY, snapToPixelProperty, widthProperty
Methods declared in class javafx.scene.Parent
getBaselineOffset, getChildrenUnmodifiable, getManagedChildren, getStylesheets, isNeedsLayout, layout, layoutChildren, needsLayoutProperty, requestLayout, requestParentLayout, setNeedsLayout, updateBounds
Methods declared in class javafx.scene.Node
accessibleHelpProperty, accessibleRoleDescriptionProperty, accessibleRoleProperty, accessibleTextProperty, addEventFilter, addEventHandler, applyCss, autosize, blendModeProperty, boundsInLocalProperty, boundsInParentProperty, buildEventDispatchChain, cacheHintProperty, cacheProperty, clipProperty, computeAreaInScreen, contains, contains, cursorProperty, depthTestProperty, disabledProperty, disableProperty, effectiveNodeOrientationProperty, effectProperty, eventDispatcherProperty, executeAccessibleAction, fireEvent, focusedProperty, focusTraversableProperty, focusVisibleProperty, focusWithinProperty, getAccessibleHelp, getAccessibleRole, getAccessibleRoleDescription, getAccessibleText, getBlendMode, getBoundsInLocal, getBoundsInParent, getCacheHint, getClip, getContentBias, getCursor, getDepthTest, getEffect, getEffectiveNodeOrientation, getEventDispatcher, getId, getInitialCursor, getInitialFocusTraversable, getInputMethodRequests, getLayoutBounds, getLayoutX, getLayoutY, getLocalToParentTransform, getLocalToSceneTransform, getNodeOrientation, getOnContextMenuRequested, getOnDragDetected, getOnDragDone, getOnDragDropped, getOnDragEntered, getOnDragExited, getOnDragOver, getOnInputMethodTextChanged, getOnKeyPressed, getOnKeyReleased, getOnKeyTyped, getOnMouseClicked, getOnMouseDragEntered, getOnMouseDragExited, getOnMouseDragged, getOnMouseDragOver, getOnMouseDragReleased, getOnMouseEntered, getOnMouseExited, getOnMouseMoved, getOnMousePressed, getOnMouseReleased, getOnRotate, getOnRotationFinished, getOnRotationStarted, getOnScroll, getOnScrollFinished, getOnScrollStarted, getOnSwipeDown, getOnSwipeLeft, getOnSwipeRight, getOnSwipeUp, getOnTouchMoved, getOnTouchPressed, getOnTouchReleased, getOnTouchStationary, getOnZoom, getOnZoomFinished, getOnZoomStarted, getOpacity, getParent, getProperties, getPseudoClassStates, getRotate, getRotationAxis, getScaleX, getScaleY, getScaleZ, getScene, getStyle, getStyleableParent, getStyleClass, getTransforms, getTranslateX, getTranslateY, getTranslateZ, getTypeSelector, getUserData, getViewOrder, hasProperties, hoverProperty, idProperty, inputMethodRequestsProperty, intersects, intersects, isCache, isDisable, isDisabled, isFocused, isFocusTraversable, isFocusVisible, isFocusWithin, isHover, isManaged, isMouseTransparent, isPickOnBounds, isPressed, isVisible, layoutBoundsProperty, layoutXProperty, layoutYProperty, localToParent, localToParent, localToParent, localToParent, localToParent, localToParentTransformProperty, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToSceneTransformProperty, localToScreen, localToScreen, localToScreen, localToScreen, localToScreen, lookup, lookupAll, managedProperty, mouseTransparentProperty, nodeOrientationProperty, notifyAccessibleAttributeChanged, onContextMenuRequestedProperty, onDragDetectedProperty, onDragDoneProperty, onDragDroppedProperty, onDragEnteredProperty, onDragExitedProperty, onDragOverProperty, onInputMethodTextChangedProperty, onKeyPressedProperty, onKeyReleasedProperty, onKeyTypedProperty, onMouseClickedProperty, onMouseDragEnteredProperty, onMouseDragExitedProperty, onMouseDraggedProperty, onMouseDragOverProperty, onMouseDragReleasedProperty, onMouseEnteredProperty, onMouseExitedProperty, onMouseMovedProperty, onMousePressedProperty, onMouseReleasedProperty, onRotateProperty, onRotationFinishedProperty, onRotationStartedProperty, onScrollFinishedProperty, onScrollProperty, onScrollStartedProperty, onSwipeDownProperty, onSwipeLeftProperty, onSwipeRightProperty, onSwipeUpProperty, onTouchMovedProperty, onTouchPressedProperty, onTouchReleasedProperty, onTouchStationaryProperty, onZoomFinishedProperty, onZoomProperty, onZoomStartedProperty, opacityProperty, parentProperty, parentToLocal, parentToLocal, parentToLocal, parentToLocal, parentToLocal, pickOnBoundsProperty, pressedProperty, pseudoClassStateChanged, queryAccessibleAttribute, relocate, removeEventFilter, removeEventHandler, requestFocus, requestFocusTraversal, resizeRelocate, rotateProperty, rotationAxisProperty, scaleXProperty, scaleYProperty, scaleZProperty, sceneProperty, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, screenToLocal, screenToLocal, screenToLocal, setAccessibleHelp, setAccessibleRole, setAccessibleRoleDescription, setAccessibleText, setBlendMode, setCache, setCacheHint, setClip, setCursor, setDepthTest, setDisable, setDisabled, setEffect, setEventDispatcher, setEventHandler, setFocused, setFocusTraversable, setHover, setId, setInputMethodRequests, setLayoutX, setLayoutY, setManaged, setMouseTransparent, setNodeOrientation, setOnContextMenuRequested, setOnDragDetected, setOnDragDone, setOnDragDropped, setOnDragEntered, setOnDragExited, setOnDragOver, setOnInputMethodTextChanged, setOnKeyPressed, setOnKeyReleased, setOnKeyTyped, setOnMouseClicked, setOnMouseDragEntered, setOnMouseDragExited, setOnMouseDragged, setOnMouseDragOver, setOnMouseDragReleased, setOnMouseEntered, setOnMouseExited, setOnMouseMoved, setOnMousePressed, setOnMouseReleased, setOnRotate, setOnRotationFinished, setOnRotationStarted, setOnScroll, setOnScrollFinished, setOnScrollStarted, setOnSwipeDown, setOnSwipeLeft, setOnSwipeRight, setOnSwipeUp, setOnTouchMoved, setOnTouchPressed, setOnTouchReleased, setOnTouchStationary, setOnZoom, setOnZoomFinished, setOnZoomStarted, setOpacity, setPickOnBounds, setPressed, setRotate, setRotationAxis, setScaleX, setScaleY, setScaleZ, setStyle, setTranslateX, setTranslateY, setTranslateZ, setUserData, setViewOrder, setVisible, snapshot, snapshot, startDragAndDrop, startFullDrag, styleProperty, toBack, toFront, toString, translateXProperty, translateYProperty, translateZProperty, usesMirroring, viewOrderProperty, visibleProperty
Methods declared in class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods declared in interface javafx.css.Styleable
getStyleableNode
-
Property Details
-
graphic
The dialog graphic, presented either in the header, if one is showing, or to the left of thecontent
.- See Also:
-
header
Property representing the header area of the dialog pane. Note that if this header is set to a non-null value, that it will take up the entire top area of the DialogPane. It will also result in the DialogPane switching its layout to the 'header' layout - as outlined in theDialogPane
class javadoc.- See Also:
-
headerText
A property representing the header text for the dialog pane. The header text is lower precedence than theheader node
, meaning that if both the header node and the headerText properties are set, the header text will not be displayed in a default DialogPane instance.When headerText is set to a non-null value, this will result in the DialogPane switching its layout to the 'header' layout - as outlined in the
DialogPane
class javadoc.- See Also:
-
content
Property representing the content area of the dialog.- See Also:
-
contentText
A property representing the content text for the dialog pane. The content text is lower precedence than thecontent node
, meaning that if both the content node and the contentText properties are set, the content text will not be displayed in a default DialogPane instance.- See Also:
-
expandableContent
A property that represents the dialog expandable content area. Any Node can be placed in this area, but it will only be shown when the user clicks the 'Show Details' expandable button. This button will be added automatically when the expandable content property is non-null.- See Also:
-
expanded
Represents whether the dialogPane is expanded.- See Also:
-
-
Constructor Details
-
DialogPane
public DialogPane()Creates a new DialogPane instance with a style class of 'dialog-pane'.
-
-
Method Details
-
graphicProperty
The dialog graphic, presented either in the header, if one is showing, or to the left of thecontent
.- Returns:
- An ObjectProperty wrapping the current graphic.
- See Also:
-
getGraphic
-
setGraphic
-
getHeader
Node which acts as the dialog pane header.- Returns:
- the header of the dialog pane.
-
setHeader
Assigns the dialog pane header. Any Node can be used.- Parameters:
header
- The new header of the DialogPane.
-
headerProperty
Property representing the header area of the dialog pane. Note that if this header is set to a non-null value, that it will take up the entire top area of the DialogPane. It will also result in the DialogPane switching its layout to the 'header' layout - as outlined in theDialogPane
class javadoc.- Returns:
- the property representing the header area of the dialog pane
- See Also:
-
setHeaderText
Sets the string to show in the dialog header area. Note that the header text is lower precedence than theheader node
, meaning that if both the header node and the headerText properties are set, the header text will not be displayed in a default DialogPane instance.When headerText is set to a non-null value, this will result in the DialogPane switching its layout to the 'header' layout - as outlined in the
DialogPane
class javadoc.- Parameters:
headerText
- the string to show in the dialog header area
-
getHeaderText
Returns the currently-set header text for this DialogPane.- Returns:
- the currently-set header text for this DialogPane
-
headerTextProperty
A property representing the header text for the dialog pane. The header text is lower precedence than theheader node
, meaning that if both the header node and the headerText properties are set, the header text will not be displayed in a default DialogPane instance.When headerText is set to a non-null value, this will result in the DialogPane switching its layout to the 'header' layout - as outlined in the
DialogPane
class javadoc.- Returns:
- the property representing the header text for the dialog pane
- See Also:
-
getContent
Returns the dialog content as a Node (even if it was set as a String usingsetContentText(String)
- this was simply transformed into aNode
(most probably aLabel
).- Returns:
- dialog's content
-
setContent
Assign dialog content. Any Node can be used- Parameters:
content
- dialog's content
-
contentProperty
Property representing the content area of the dialog.- Returns:
- the property representing the content area of the dialog
- See Also:
-
setContentText
Sets the string to show in the dialog content area. Note that the content text is lower precedence than thecontent node
, meaning that if both the content node and the contentText properties are set, the content text will not be displayed in a default DialogPane instance.- Parameters:
contentText
- the string to show in the dialog content area
-
getContentText
Returns the currently-set content text for this DialogPane.- Returns:
- the currently-set content text for this DialogPane
-
contentTextProperty
A property representing the content text for the dialog pane. The content text is lower precedence than thecontent node
, meaning that if both the content node and the contentText properties are set, the content text will not be displayed in a default DialogPane instance.- Returns:
- the property representing the content text for the dialog pane
- See Also:
-
expandableContentProperty
A property that represents the dialog expandable content area. Any Node can be placed in this area, but it will only be shown when the user clicks the 'Show Details' expandable button. This button will be added automatically when the expandable content property is non-null.- Returns:
- the property that represents the dialog expandable content area
- See Also:
-
getExpandableContent
Returns the dialog expandable content node, if one is set, or null otherwise.- Returns:
- the dialog expandable content node
-
setExpandableContent
Sets the dialog expandable content node, or null if no expandable content needs to be shown.- Parameters:
content
- the dialog expandable content node
-
expandedProperty
Represents whether the dialogPane is expanded.- Returns:
- the property representing whether the dialogPane is expanded
- See Also:
-
isExpanded
public final boolean isExpanded()Returns whether or not the dialogPane is expanded.- Returns:
- true if dialogPane is expanded.
-
setExpanded
public final void setExpanded(boolean value) Sets whether the dialogPane is expanded. This only makes sense when there isexpandable content
to show.- Parameters:
value
- true if dialogPane should be expanded.
-
getButtonTypes
Observable list of button types used for the dialog button bar area (created via thecreateButtonBar()
method). Modifying the contents of this list will immediately change the buttons displayed to the user within the dialog pane.- Returns:
- The
ObservableList
ofbutton types
available to the user.
-
lookupButton
This method provides a way in which developers may retrieve the actual Node for a givenButtonType
(assuming it is part of thebutton types
list).- Parameters:
buttonType
- TheButtonType
for which a Node representation is requested.- Returns:
- The Node used to represent the button type, as created by
createButton(ButtonType)
, and only if the button type is part of thebutton types
list, otherwise null.
-
createButtonBar
This method can be overridden by subclasses to provide the button bar. Note that by overriding this method, the developer must take on multiple responsibilities:- The developer must immediately iterate through all
button types
and callcreateButton(ButtonType)
for each of them in turn. - The developer must add a listener to the
button types
list, and when this list changes update the button bar as appropriate. - Similarly, the developer must watch for changes to the
expandable content
property, adding and removing the details button (created viacreateDetailsButton()
method).
The default implementation of this method creates and returns a new
ButtonBar
instance.- Returns:
- the created button bar
- The developer must immediately iterate through all
-
createButton
This method can be overridden by subclasses to create a custom button that will subsequently inserted into the DialogPane button area (created via thecreateButtonBar()
method, but mostly commonly it is an instance ofButtonBar
.- Parameters:
buttonType
- TheButtonType
to create a button from.- Returns:
- A JavaFX
Node
that represents the givenButtonType
, most commonly an instance ofButton
.
-
createDetailsButton
This method can be overridden by subclasses to create a custom details button.To override this method you must do two things:
- The button will need to have its own code set to handle mouse / keyboard
interaction and to toggle the state of the
expanded
property. - If your button changes its visuals based on whether the dialog pane
is expanded or collapsed, you should add a listener to the
expanded
property, so that you may update the button visuals.
- Returns:
- the created details button
- The button will need to have its own code set to handle mouse / keyboard
interaction and to toggle the state of the
-
getClassCssMetaData
Gets theCssMetaData
associated with this class, which may include theCssMetaData
of its superclasses.- Returns:
- the
CssMetaData
-