public class DialogPane
extends Pane
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
Type | Property and Description |
---|---|
<any> |
content
Property representing the content area of the dialog.
|
StringProperty |
contentText
A property representing the content text for the dialog pane.
|
<any> |
expandableContent
A property that represents the dialog expandable content area.
|
BooleanProperty |
expanded
Represents whether the dialogPane is expanded.
|
<any> |
graphic
The dialog graphic, presented either in the header, if one is showing, or
to the left of the
content . |
<any> |
header
Property representing the header area of the dialog pane.
|
StringProperty |
headerText
A property representing the header text for the dialog pane.
|
private StyleableStringProperty |
imageUrl
The imageUrl property is set from CSS and then the graphic property is
set from the invalidated method.
|
Modifier and Type | Class and Description |
---|---|
private static class |
DialogPane.StyleableProperties
*
Stylesheet Handling *
*
|
Modifier and Type | Field and Description |
---|---|
private Node |
buttonBar |
private java.util.Map<ButtonType,Node> |
buttonNodes |
private <any> |
buttons |
private <any> |
content |
private Label |
contentLabel |
private StringProperty |
contentText |
private Node |
detailsButton |
private Dialog<?> |
dialog |
private <any> |
expandableContentProperty |
private BooleanProperty |
expandedProperty |
private StackPane |
graphicContainer |
private <any> |
graphicProperty
Properties
|
private <any> |
header |
private StringProperty |
headerText |
private GridPane |
headerTextPanel
Private fields
|
private StyleableStringProperty |
imageUrl |
private double |
oldHeight |
Constructor and Description |
---|
DialogPane()
Creates a new DialogPane instance with a style class of 'dialog-pane'.
|
Modifier and Type | Method and Description |
---|---|
protected double |
computeMinHeight(double width) |
protected double |
computeMinWidth(double height) |
protected double |
computePrefHeight(double width) |
protected double |
computePrefWidth(double height) |
<any> |
contentProperty()
Property representing the content area of the dialog.
|
StringProperty |
contentTextProperty()
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
the
createButtonBar() method, but mostly commonly it is an instance
of ButtonBar . |
protected Node |
createButtonBar()
This method can be overridden by subclasses to provide the button bar.
|
(package private) static Label |
createContentLabel(java.lang.String text)
Creates a Label node that works well within a Dialog.
|
protected Node |
createDetailsButton()
This method can be overridden by subclasses to create a custom details button.
|
<any> |
expandableContentProperty()
A property that represents the dialog expandable content area.
|
BooleanProperty |
expandedProperty()
Represents whether the dialogPane is expanded.
|
private Node |
getActualContent() |
private Node |
getActualGraphic() |
private Node |
getActualHeader() |
<any> |
getButtonTypes()
Observable list of button types used for the dialog button bar area
(created via the
createButtonBar() method). |
static java.util.List<<any>> |
getClassCssMetaData() |
Node |
getContent()
Returns the dialog content as a Node (even if it was set as a String
using
setContentText(String) - this was simply transformed into a
Node (most probably a Label ). |
java.lang.String |
getContentText()
Returns the currently-set content text for this DialogPane.
|
java.util.List<<any>> |
getCssMetaData() |
Node |
getExpandableContent()
Returns the dialog expandable content node, if one is set, or null
otherwise.
|
Node |
getGraphic()
Gets the value of the property graphic.
|
Node |
getHeader()
Node which acts as the dialog pane header.
|
java.lang.String |
getHeaderText()
Returns the currently-set header text for this DialogPane.
|
<any> |
graphicProperty()
The dialog graphic, presented either in the header, if one is showing, or
to the left of the
content . |
(package private) boolean |
hasExpandableContent() |
(package private) boolean |
hasHeader() |
<any> |
headerProperty()
Property representing the header area of the dialog pane.
|
StringProperty |
headerTextProperty()
A 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.
|
boolean |
isExpanded()
Returns whether or not the dialogPane is expanded.
|
private boolean |
isTextHeader() |
protected void |
layoutChildren() |
Node |
lookupButton(ButtonType buttonType)
This method provides a way in which developers may retrieve the actual
Node for a given
ButtonType (assuming it is part of the
button types list). |
void |
setContent(Node content)
Assign dialog content.
|
void |
setContentText(java.lang.String contentText)
Sets the string to show in the dialog content area.
|
(package private) void |
setDialog(Dialog<?> dialog) |
void |
setExpandableContent(Node content)
Sets the dialog expandable content node, or null if no expandable content
needs to be shown.
|
void |
setExpanded(boolean value)
Sets whether the dialogPane is expanded.
|
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
content . |
void |
setHeader(Node header)
Assigns the dialog pane header.
|
void |
setHeaderText(java.lang.String headerText)
Sets the string to show in the dialog header area.
|
private void |
updateButtons(ButtonBar buttonBar)
Private implementation
|
private void |
updateContentArea() |
private void |
updateHeaderArea() |
public final <any> graphicProperty
content
.getGraphic()
,
setGraphic(Node)
private StyleableStringProperty imageUrlProperty
public final <any> headerProperty
DialogPane
class
javadoc.getHeader()
,
setHeader(Node)
public final StringProperty headerTextProperty
header 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.
getHeaderText()
,
setHeaderText(String)
public final <any> contentProperty
getContent()
,
setContent(Node)
public final StringProperty contentTextProperty
content 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.getContentText()
,
setContentText(String)
public final <any> expandableContentProperty
getExpandableContent()
,
setExpandableContent(Node)
public final BooleanProperty expandedProperty
isExpanded()
,
setExpanded(boolean)
private final GridPane headerTextPanel
private final Label contentLabel
private final StackPane graphicContainer
private final Node buttonBar
private final <any> buttons
private final java.util.Map<ButtonType,Node> buttonNodes
private Node detailsButton
private Dialog<?> dialog
private final <any> graphicProperty
private StyleableStringProperty imageUrl
private final <any> header
private final StringProperty headerText
private final <any> content
private final StringProperty contentText
private final <any> expandableContentProperty
private final BooleanProperty expandedProperty
private double oldHeight
public DialogPane()
static Label createContentLabel(java.lang.String text)
text
- The text to displaypublic final <any> graphicProperty()
content
.getGraphic()
,
setGraphic(Node)
public final Node getGraphic()
public final void setGraphic(Node graphic)
content
.graphic
- The new dialog graphic, or null if no graphic should be shown.private StyleableStringProperty imageUrlProperty()
public final Node getHeader()
public final void setHeader(Node header)
header
- The new header of the DialogPane.public final <any> headerProperty()
DialogPane
class
javadoc.getHeader()
,
setHeader(Node)
public final void setHeaderText(java.lang.String headerText)
header 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.
headerText
- the string to show in the dialog header areapublic final java.lang.String getHeaderText()
public final StringProperty headerTextProperty()
header 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.
getHeaderText()
,
setHeaderText(String)
public final Node getContent()
setContentText(String)
- this was simply transformed into a
Node
(most probably a Label
).public final void setContent(Node content)
content
- dialog's contentpublic final <any> contentProperty()
getContent()
,
setContent(Node)
public final void setContentText(java.lang.String contentText)
content 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.contentText
- the string to show in the dialog content areapublic final java.lang.String getContentText()
public final StringProperty contentTextProperty()
content 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.getContentText()
,
setContentText(String)
public final <any> expandableContentProperty()
getExpandableContent()
,
setExpandableContent(Node)
public final Node getExpandableContent()
public final void setExpandableContent(Node content)
content
- the dialog expandable content nodepublic final BooleanProperty expandedProperty()
isExpanded()
,
setExpanded(boolean)
public final boolean isExpanded()
public final void setExpanded(boolean value)
expandable content
to show.value
- true if dialogPane should be expanded.public final <any> getButtonTypes()
createButtonBar()
method). Modifying the contents
of this list will immediately change the buttons displayed to the user
within the dialog pane.ObservableList
of button types
available to the user.public final Node lookupButton(ButtonType buttonType)
ButtonType
(assuming it is part of the
button types
list).buttonType
- The ButtonType
for which a Node representation is requested.createButton(ButtonType)
, and only if the button type
is part of the button types
list, otherwise null.protected Node createButtonBar()
button types
and call
createButton(ButtonType)
for each of them in turn.
button types
list, and when this list changes
update the button bar as appropriate.
expandable content
property,
adding and removing the details button (created via
createDetailsButton()
method).
The default implementation of this method creates and returns a new
ButtonBar
instance.
protected Node createButton(ButtonType buttonType)
createButtonBar()
method, but mostly commonly it is an instance
of ButtonBar
.buttonType
- The ButtonType
to create a button from.Node
that represents the given ButtonType
,
most commonly an instance of Button
.protected Node createDetailsButton()
To override this method you must do two things:
expanded
property.
expanded
property, so that you may update
the button visuals.
protected void layoutChildren()
protected double computeMinWidth(double height)
protected double computeMinHeight(double width)
protected double computePrefWidth(double height)
protected double computePrefHeight(double width)
private void updateButtons(ButtonBar buttonBar)
buttonBar
- private Node getActualContent()
private Node getActualHeader()
private Node getActualGraphic()
private void updateHeaderArea()
private void updateContentArea()
boolean hasHeader()
private boolean isTextHeader()
boolean hasExpandableContent()
void setDialog(Dialog<?> dialog)
public static java.util.List<<any>> getClassCssMetaData()
public java.util.List<<any>> getCssMetaData()