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 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:
header property takes precedence over the headerText
property, so if both are set to non-null values, header will be
used and headerText will be ignored.headerText is set to a non-null value, and a
graphic 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.header is set to a non-null value, and a
graphic 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.
Dialog
| Modifier and Type | Class and Description |
|---|---|
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private final Node | |
| private final Map | |
| private final ObservableList | |
| private final ObjectProperty | |
| private final Label | |
| private final StringProperty | |
| private Node | |
| private Dialog | |
| private final ObjectProperty | |
| private final BooleanProperty | |
| private final StackPane | |
| private final ObjectProperty | |
| private final ObjectProperty | |
| private final StringProperty | |
| private final GridPane | |
| private StyleableStringProperty | |
| private double |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected double | computeMinHeight(double
the width that should be used if min height depends
on it width)Overrides javafx. Computes the minimum height of this region. |
| protected double | computeMinWidth(double
the height that should be used if min width depends
on it height)Overrides javafx. Computes the minimum width of this region. |
| protected double | computePrefHeight(double
the width that should be used if preferred height depends
on it width)Overrides javafx. Computes the preferred height of this region for the given width; Region subclasses should override this method to return an appropriate value based on their content and layout strategy. |
| protected double | computePrefWidth(double
the height that should be used if preferred width depends
on it height)Overrides javafx. Computes the preferred width of this region for the given height. |
| public final ObjectProperty | Returns: the property representing the content area of the dialogProperty representing the content area of the dialog. |
| public final StringProperty | Returns: the property representing the content text for the dialog paneA property representing the content text for the dialog pane. |
| protected Node | createButton(ButtonType
The buttonType)ButtonType to create a button from.This method can be overridden by subclasses to create a custom button that
will subsequently inserted into the DialogPane button area (created via
the |
| protected Node | Returns: the created button barThis method can be overridden by subclasses to provide the button bar. |
| pack-priv static Label | createContentLabel(String
The text to display text)Creates a Label node that works well within a Dialog. |
| protected Node | Returns: the created details buttonThis method can be overridden by subclasses to create a custom details button. |
| public final ObjectProperty | Returns: the property that represents the dialog expandable content areaA property that represents the dialog expandable content area. |
| public final BooleanProperty | Returns: the property representing whether the dialogPane is expandedRepresents whether the dialogPane is expanded. |
| private Node | |
| private Node | |
| private Node | |
| public final ObservableList | getButtonTypes()
Observable list of button types used for the dialog button bar area
(created via the |
| public static List | Returns: theCssMetaDataHides javafx. Gets the |
| public final Node | Returns: dialog's contentReturns the dialog content as a Node (even if it was set as a String
using |
| public final String | Returns: the currently-set content text for this DialogPaneReturns the currently-set content text for this DialogPane. |
| public List | getCssMetaData()
Overrides javafx. Implements javafx. This method should delegate to |
| public final Node | Returns: the dialog expandable content nodeReturns the dialog expandable content node, if one is set, or null otherwise. |
| public final Node | |
| public final Node | |
| public final String | Returns: the currently-set header text for this DialogPaneReturns the currently-set header text for this DialogPane. |
| public final ObjectProperty | Returns: An ObjectProperty wrapping the current graphic.The dialog graphic, presented either in the header, if one is showing, or
to the left of the |
| pack-priv boolean | |
| pack-priv boolean | |
| public final ObjectProperty | Returns: the property representing the header area of the dialog paneProperty representing the header area of the dialog pane. |
| public final StringProperty | Returns: the property representing the header text for the dialog paneA property representing the header text for the dialog pane. |
| private StyleableStringProperty | imageUrlProperty()
The imageUrl property is set from CSS and then the graphic property is set from the invalidated method. |
| public final boolean | Returns: true if dialogPane is expanded.Returns whether or not the dialogPane is expanded. |
| private boolean | |
| protected void | layoutChildren()
Overrides javafx. Invoked during the layout pass to layout the children in this
|
| public final Node | Returns: The Node used to represent the button type, as created bycreateButton(ButtonType), and only if the button type
is part of the button types list, otherwise null.The buttonType)ButtonType for which a Node representation is requested.This method provides a way in which developers may retrieve the actual
Node for a given |
| public final void | |
| public final void | setContentText(String
the string to show in the dialog content area contentText)Sets the string to show in the dialog content area. |
| pack-priv void | |
| public final void | setExpandableContent(Node
the dialog expandable content node content)Sets the dialog expandable content node, or null if no expandable content needs to be shown. |
| public final void | setExpanded(boolean
true if dialogPane should be expanded. value)Sets whether the dialogPane is expanded. |
| public final void | setGraphic(Node
The new dialog graphic, or null if no graphic should be shown. graphic)Sets the dialog graphic, which will be displayed either in the header, if
one is showing, or to the left of the |
| public final void | |
| public final void | setHeaderText(String
the string to show in the dialog header area headerText)Sets the string to show in the dialog header area. |
| private void | |
| private void | |
| private void |
| buttonBar | back to summary |
|---|---|
| private final Node buttonBar | |
| buttonNodes | back to summary |
|---|---|
| private final Map<ButtonType, Node> buttonNodes | |
| buttons | back to summary |
|---|---|
| private final ObservableList<ButtonType> buttons | |
| content | back to summary |
|---|---|
| private final ObjectProperty<Node> content | |
| contentLabel | back to summary |
|---|---|
| private final Label contentLabel | |
| contentText | back to summary |
|---|---|
| private final StringProperty contentText | |
| detailsButton | back to summary |
|---|---|
| private Node detailsButton | |
| dialog | back to summary |
|---|---|
| private Dialog<?> dialog | |
| expandableContentProperty | back to summary |
|---|---|
| private final ObjectProperty<Node> expandableContentProperty | |
| expandedProperty | back to summary |
|---|---|
| private final BooleanProperty expandedProperty | |
| graphicContainer | back to summary |
|---|---|
| private final StackPane graphicContainer | |
| graphicProperty | back to summary |
|---|---|
| private final ObjectProperty<Node> graphicProperty | |
| header | back to summary |
|---|---|
| private final ObjectProperty<Node> header | |
| headerText | back to summary |
|---|---|
| private final StringProperty headerText | |
| headerTextPanel | back to summary |
|---|---|
| private final GridPane headerTextPanel | |
| imageUrl | back to summary |
|---|---|
| private StyleableStringProperty imageUrl | |
| oldHeight | back to summary |
|---|---|
| private double oldHeight | |
| DialogPane | back to summary |
|---|---|
| public DialogPane() Creates a new DialogPane instance with a style class of 'dialog-pane'. | |
| computeMinHeight | back to summary |
|---|---|
| protected double computeMinHeight(double width) Overrides javafx. Doc from javafx. Computes the minimum height of this region. Returns the sum of the top and bottom insets by default. Region subclasses should override this method to return an appropriate value based on their content and layout strategy. If the subclass doesn't have a HORIZONTAL content bias, then the width parameter can be ignored.
| |
| computeMinWidth | back to summary |
|---|---|
| protected double computeMinWidth(double height) Overrides javafx. Doc from javafx. Computes the minimum width of this region. Returns the sum of the left and right insets by default. region subclasses should override this method to return an appropriate value based on their content and layout strategy. If the subclass doesn't have a VERTICAL content bias, then the height parameter can be ignored.
| |
| computePrefHeight | back to summary |
|---|---|
| protected double computePrefHeight(double width) Overrides javafx. Doc from javafx. Computes the preferred height of this region for the given width; Region subclasses should override this method to return an appropriate value based on their content and layout strategy. If the subclass doesn't have a HORIZONTAL content bias, then the width parameter can be ignored.
| |
| computePrefWidth | back to summary |
|---|---|
| protected double computePrefWidth(double height) Overrides javafx. Doc from javafx. Computes the preferred width of this region for the given height. Region subclasses should override this method to return an appropriate value based on their content and layout strategy. If the subclass doesn't have a VERTICAL content bias, then the height parameter can be ignored.
| |
| contentProperty | back to summary |
|---|---|
| public final ObjectProperty Property representing the content area of the dialog.
| |
| contentTextProperty | back to summary |
|---|---|
| public final StringProperty contentTextProperty() A property representing the content text for the dialog pane. The content text
is lower precedence than the
| |
| createButton | back to summary |
|---|---|
| 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
the
| |
| createButtonBar | back to summary |
|---|---|
| protected Node 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 default implementation of this method creates and returns a new
| |
| createContentLabel | back to summary |
|---|---|
| pack-priv static Label createContentLabel(String text) Creates a Label node that works well within a Dialog.
| |
| createDetailsButton | back to summary |
|---|---|
| protected Node createDetailsButton() This method can be overridden by subclasses to create a custom details button. To override this method you must do two things:
| |
| expandableContentProperty | back to summary |
|---|---|
| public final ObjectProperty 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.
| |
| expandedProperty | back to summary |
|---|---|
| public final BooleanProperty expandedProperty() Represents whether the dialogPane is expanded.
| |
| getActualContent | back to summary |
|---|---|
| private Node getActualContent() | |
| getActualGraphic | back to summary |
|---|---|
| private Node getActualGraphic() | |
| getActualHeader | back to summary |
|---|---|
| private Node getActualHeader() | |
| getButtonTypes | back to summary |
|---|---|
| public final ObservableList Observable list of button types used for the dialog button bar area
(created via the
| |
| getClassCssMetaData | back to summary |
|---|---|
| public static List Hides javafx. Gets the
| |
| getContent | back to summary |
|---|---|
| public final Node getContent() Returns the dialog content as a Node (even if it was set as a String
using
| |
| getContentText | back to summary |
|---|---|
| public final String getContentText() Returns the currently-set content text for this DialogPane.
| |
| getCssMetaData | back to summary |
|---|---|
| public List Overrides javafx. Implements javafx. Doc from javafx. This method should delegate to
| |
| getExpandableContent | back to summary |
|---|---|
| public final Node getExpandableContent() Returns the dialog expandable content node, if one is set, or null otherwise.
| |
| getGraphic | back to summary |
|---|---|
| public final Node getGraphic() | |
| getHeader | back to summary |
|---|---|
| public final Node getHeader() Node which acts as the dialog pane header.
| |
| getHeaderText | back to summary |
|---|---|
| public final String getHeaderText() Returns the currently-set header text for this DialogPane.
| |
| graphicProperty | back to summary |
|---|---|
| public final ObjectProperty The dialog graphic, presented either in the header, if one is showing, or
to the left of the
| |
| hasExpandableContent | back to summary |
|---|---|
| pack-priv boolean hasExpandableContent() | |
| hasHeader | back to summary |
|---|---|
| pack-priv boolean hasHeader() | |
| headerProperty | back to summary |
|---|---|
| public final ObjectProperty 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 the
| |
| headerTextProperty | back to summary |
|---|---|
| public final StringProperty headerTextProperty() A property representing the header text for the dialog pane. The header text
is lower precedence than the 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
| |
| imageUrlProperty | back to summary |
|---|---|
| private StyleableStringProperty imageUrlProperty() The imageUrl property is set from CSS and then the graphic property is set from the invalidated method. This ensures that the same image isn't reloaded. | |
| isExpanded | back to summary |
|---|---|
| public final boolean isExpanded() Returns whether or not the dialogPane is expanded.
| |
| isTextHeader | back to summary |
|---|---|
| private boolean isTextHeader() | |
| layoutChildren | back to summary |
|---|---|
| protected void layoutChildren() Overrides javafx. Doc from javafx. Invoked during the layout pass to layout the children in this
Subclasses should override this function to layout content as needed.
| |
| lookupButton | back to summary |
|---|---|
| public final Node lookupButton(ButtonType buttonType) This method provides a way in which developers may retrieve the actual
Node for a given
| |
| setContent | back to summary |
|---|---|
| public final void setContent(Node content) Assign dialog content. Any Node can be used
| |
| setContentText | back to summary |
|---|---|
| public final void setContentText(String contentText) Sets the string to show in the dialog content area. Note that the content text
is lower precedence than the
| |
| setDialog | back to summary |
|---|---|
| pack-priv void setDialog(Dialog<?> dialog) | |
| setExpandableContent | back to summary |
|---|---|
| public final void setExpandableContent(Node content) Sets the dialog expandable content node, or null if no expandable content needs to be shown.
| |
| setExpanded | back to summary |
|---|---|
| public final void setExpanded(boolean value) Sets whether the dialogPane is expanded. This only makes sense when there
is
| |
| setGraphic | back to summary |
|---|---|
| public 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 the
| |
| setHeader | back to summary |
|---|---|
| public final void setHeader(Node header) Assigns the dialog pane header. Any Node can be used.
| |
| setHeaderText | back to summary |
|---|---|
| public final void setHeaderText(String headerText) Sets the string to show in the dialog header area. Note that the header text
is lower precedence than the 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
| |
| updateButtons | back to summary |
|---|---|
| private void updateButtons(ButtonBar buttonBar) | |
| updateContentArea | back to summary |
|---|---|
| private void updateContentArea() | |
| updateHeaderArea | back to summary |
|---|---|
| private void updateHeaderArea() | |
| Modifier and Type | Field and Description |
|---|---|
| private static final CssMetaData | |
| private static final List |
| Access | Constructor and Description |
|---|---|
| private |
| GRAPHIC | back to summary |
|---|---|
| private static final CssMetaData<DialogPane, String> GRAPHIC | |
| STYLEABLES | back to summary |
|---|---|
| private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES | |
| StyleableProperties | back to summary |
|---|---|
| private StyleableProperties() | |