java.lang.Object
javafx.stage.Window
javafx.stage.PopupWindow
javafx.scene.control.PopupControl
javafx.scene.control.Tooltip
- All Implemented Interfaces:
Styleable
,EventTarget
,Skinnable
Tooltips are common UI elements which are typically used for showing
additional information about a Node in the scenegraph when the Node is
hovered over by the mouse. Any Node can show a tooltip. In most cases a
Tooltip is created and its
text
property is modified
to show plain text to the user. However, a Tooltip is able to show within it
an arbitrary scenegraph of nodes - this is done by creating the scenegraph
and setting it inside the Tooltip graphic
property.
You use the following approach to set a Tooltip on any node:
Rectangle rect = new Rectangle(0, 0, 100, 100); Tooltip t = new Tooltip("A Square"); Tooltip.install(rect, t);This tooltip will then participate with the typical tooltip semantics (i.e. appearing on hover, etc). Note that the Tooltip does not have to be uninstalled: it will be garbage collected when it is not referenced by any Node. It is possible to manually uninstall the tooltip, however.
A single tooltip can be installed on multiple target nodes or multiple controls.
Because most Tooltips are shown on UI controls, there is special API for all controls to make installing a Tooltip less verbose. The example below shows how to create a tooltip for a Button control:
Button button = new Button("Hover Over Me"); button.setTooltip(new Tooltip("Tooltip for Button"));
- Since:
- JavaFX 2.0
-
Property Summary
TypePropertyDescriptionfinal ReadOnlyBooleanProperty
Typically, the tooltip is "activated" when the mouse moves over a Control.final ObjectProperty<ContentDisplay>
Specifies the positioning of the graphic relative to the text.final ObjectProperty<Font>
The default font to use for text in the Tooltip.final ObjectProperty<Node>
An optional icon for the Tooltip.final DoubleProperty
The amount of space between the graphic and textfinal ObjectProperty<Duration>
The duration in which to continue showing the tooltip after the mouse has left the node.final ObjectProperty<Duration>
The delay between the mouse entering the hovered node and when the associated tooltip will be shown to the user.final ObjectProperty<Duration>
The duration that the tooltip should remain showing for until it is no longer visible to the user.final ObjectProperty<TextAlignment>
Specifies the behavior for lines of text when text is multiline.final ObjectProperty<OverrunStyle>
Specifies the behavior to use if the text of theTooltip
exceeds the available space for rendering the text.final StringProperty
The text to display in the tooltip.final BooleanProperty
If a run of text exceeds the width of the Tooltip, then this variable indicates whether the text should wrap onto another line.Properties declared in class javafx.scene.control.PopupControl
id, maxHeight, maxWidth, minHeight, minWidth, prefHeight, prefWidth, skin, style
Properties declared in class javafx.stage.PopupWindow
anchorLocation, anchorX, anchorY, autoFix, autoHide, consumeAutoHidingEvents, hideOnEscape, onAutoHide, ownerNode, ownerWindow
Properties declared in class javafx.stage.Window
eventDispatcher, focused, forceIntegerRenderScale, height, onCloseRequest, onHidden, onHiding, onShowing, onShown, opacity, outputScaleX, outputScaleY, renderScaleX, renderScaleY, scene, showing, width, x, y
-
Nested Class Summary
Nested classes/interfaces declared in class javafx.stage.PopupWindow
PopupWindow.AnchorLocation
-
Field Summary
Fields declared in class javafx.scene.control.PopupControl
bridge, USE_COMPUTED_SIZE, USE_PREF_SIZE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal ReadOnlyBooleanProperty
Typically, the tooltip is "activated" when the mouse moves over a Control.final ObjectProperty<ContentDisplay>
Specifies the positioning of the graphic relative to the text.final ObjectProperty<Font>
The default font to use for text in the Tooltip.static List<CssMetaData<? extends Styleable,
?>> Gets theCssMetaData
associated with this class, which may include theCssMetaData
of its superclasses.final ContentDisplay
Gets the value of the property contentDisplay.List<CssMetaData<? extends Styleable,
?>> The CssMetaData of this Styleable.final Font
getFont()
Gets the value of the property font.final Node
Gets the value of the property graphic.final double
Gets the value of the property graphicTextGap.final Duration
Gets the value of the property hideDelay.final Duration
Gets the value of the property showDelay.final Duration
Gets the value of the property showDuration.final String
getText()
Gets the value of the property text.final TextAlignment
Gets the value of the property textAlignment.final OverrunStyle
Gets the value of the property textOverrun.final ObjectProperty<Node>
An optional icon for the Tooltip.final DoubleProperty
The amount of space between the graphic and textfinal ObjectProperty<Duration>
The duration in which to continue showing the tooltip after the mouse has left the node.static void
final boolean
Gets the value of the property activated.final boolean
Gets the value of the property wrapText.final void
setContentDisplay
(ContentDisplay value) Sets the value of the property contentDisplay.final void
Sets the value of the property font.final void
setGraphic
(Node value) Sets the value of the property graphic.final void
setGraphicTextGap
(double value) Sets the value of the property graphicTextGap.final void
setHideDelay
(Duration hideDelay) Sets the value of the property hideDelay.final void
setShowDelay
(Duration showDelay) Sets the value of the property showDelay.final void
setShowDuration
(Duration showDuration) Sets the value of the property showDuration.final void
Sets the value of the property text.final void
setTextAlignment
(TextAlignment value) Sets the value of the property textAlignment.final void
setTextOverrun
(OverrunStyle value) Sets the value of the property textOverrun.final void
setWrapText
(boolean value) Sets the value of the property wrapText.final ObjectProperty<Duration>
The delay between the mouse entering the hovered node and when the associated tooltip will be shown to the user.final ObjectProperty<Duration>
The duration that the tooltip should remain showing for until it is no longer visible to the user.final ObjectProperty<TextAlignment>
Specifies the behavior for lines of text when text is multiline.final ObjectProperty<OverrunStyle>
Specifies the behavior to use if the text of theTooltip
exceeds the available space for rendering the text.final StringProperty
The text to display in the tooltip.static void
final BooleanProperty
If a run of text exceeds the width of the Tooltip, then this variable indicates whether the text should wrap onto another line.Methods declared in class javafx.scene.control.PopupControl
createDefaultSkin, getId, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getPrefHeight, getPrefWidth, getPseudoClassStates, getSkin, getStyle, getStyleableParent, getStyleClass, getTypeSelector, idProperty, maxHeight, maxHeightProperty, maxWidth, maxWidthProperty, minHeight, minHeightProperty, minWidth, minWidthProperty, prefHeight, prefHeightProperty, prefWidth, prefWidthProperty, pseudoClassStateChanged, setId, setMaxHeight, setMaxSize, setMaxWidth, setMinHeight, setMinSize, setMinWidth, setPrefHeight, setPrefSize, setPrefWidth, setSkin, setStyle, skinProperty, styleProperty
Methods declared in class javafx.stage.PopupWindow
anchorLocationProperty, anchorXProperty, anchorYProperty, autoFixProperty, autoHideProperty, consumeAutoHidingEventsProperty, getAnchorLocation, getAnchorX, getAnchorY, getConsumeAutoHidingEvents, getOnAutoHide, getOwnerNode, getOwnerWindow, hide, hideOnEscapeProperty, isAutoFix, isAutoHide, isHideOnEscape, onAutoHideProperty, ownerNodeProperty, ownerWindowProperty, setAnchorLocation, setAnchorX, setAnchorY, setAutoFix, setAutoHide, setConsumeAutoHidingEvents, setHideOnEscape, setOnAutoHide, setScene, show, show, show
Methods declared in class javafx.stage.Window
addEventFilter, addEventHandler, buildEventDispatchChain, centerOnScreen, eventDispatcherProperty, fireEvent, focusedProperty, forceIntegerRenderScaleProperty, getEventDispatcher, getHeight, getOnCloseRequest, getOnHidden, getOnHiding, getOnShowing, getOnShown, getOpacity, getOutputScaleX, getOutputScaleY, getProperties, getRenderScaleX, getRenderScaleY, getScene, getUserData, getWidth, getWindows, getX, getY, hasProperties, heightProperty, isFocused, isForceIntegerRenderScale, isShowing, onCloseRequestProperty, onHiddenProperty, onHidingProperty, onShowingProperty, onShownProperty, opacityProperty, outputScaleXProperty, outputScaleYProperty, removeEventFilter, removeEventHandler, renderScaleXProperty, renderScaleYProperty, requestFocus, sceneProperty, setEventDispatcher, setEventHandler, setForceIntegerRenderScale, setHeight, setOnCloseRequest, setOnHidden, setOnHiding, setOnShowing, setOnShown, setOpacity, setRenderScaleX, setRenderScaleY, setUserData, setWidth, setX, setY, show, showingProperty, sizeToScene, widthProperty, xProperty, yProperty
Methods declared in class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods declared in interface javafx.css.Styleable
getStyleableNode
-
Property Details
-
text
The text to display in the tooltip. If the text is set to null, an empty string will be displayed, despite the value being null.- See Also:
-
textAlignment
Specifies the behavior for lines of text when text is multiline. UnlikecontentDisplay
which affects the graphic and text, this setting only affects multiple lines of text relative to the text bounds. -
textOverrun
Specifies the behavior to use if the text of theTooltip
exceeds the available space for rendering the text.- See Also:
-
wrapText
If a run of text exceeds the width of the Tooltip, then this variable indicates whether the text should wrap onto another line.- See Also:
-
font
The default font to use for text in the Tooltip. If the Tooltip's text is rich text then this font may or may not be used depending on the font information embedded in the rich text, but in any case where a default font is required, this font will be used.- See Also:
-
showDelay
The delay between the mouse entering the hovered node and when the associated tooltip will be shown to the user. The default delay is 1000ms.- Default value:
- 1000ms
- Since:
- 9
- See Also:
-
showDuration
The duration that the tooltip should remain showing for until it is no longer visible to the user. If the mouse leaves the control before the showDuration finishes, then the tooltip will remain showing for the duration specified in thehideDelayProperty()
, even if the remaining time of the showDuration is less than the hideDelay duration. The default value is 5000ms.- Default value:
- 5000ms
- Since:
- 9
- See Also:
-
hideDelay
The duration in which to continue showing the tooltip after the mouse has left the node. Once this time has elapsed the tooltip will hide. The default value is 200ms.- Default value:
- 200ms
- Since:
- 9
- See Also:
-
graphic
An optional icon for the Tooltip. This can be positioned relative to the text by using thecontent display
property. The node specified for this variable cannot appear elsewhere in the scene graph, otherwise theIllegalArgumentException
is thrown. See the class description ofNode
for more detail.- See Also:
-
contentDisplay
Specifies the positioning of the graphic relative to the text. -
graphicTextGap
The amount of space between the graphic and text- See Also:
-
activated
Typically, the tooltip is "activated" when the mouse moves over a Control. There is usually some delay between when the Tooltip becomes "activated" and when it is actually shown. The details (such as the amount of delay, etc) is left to the Skin implementation.- See Also:
-
-
Constructor Details
-
Tooltip
public Tooltip()Creates a tooltip with an empty string for its text. -
Tooltip
Creates a tooltip with the specified text.- Parameters:
text
- A text string for the tooltip.
-
-
Method Details
-
install
Associates the givenTooltip
with the givenNode
. The tooltip can then behave similar to when it is set on anyControl
. A single tooltip can be associated with multiple nodes.- Parameters:
node
- the nodet
- the tooltip- See Also:
-
uninstall
Removes the association of the givenTooltip
on the specifiedNode
. Hence hovering on the node will no longer result in showing of the tooltip.- Parameters:
node
- the nodet
- the tooltip- See Also:
-
textProperty
The text to display in the tooltip. If the text is set to null, an empty string will be displayed, despite the value being null.- See Also:
-
setText
Sets the value of the property text.- Property description:
- The text to display in the tooltip. If the text is set to null, an empty string will be displayed, despite the value being null.
-
getText
Gets the value of the property text.- Property description:
- The text to display in the tooltip. If the text is set to null, an empty string will be displayed, despite the value being null.
-
textAlignmentProperty
Specifies the behavior for lines of text when text is multiline. UnlikecontentDisplay
which affects the graphic and text, this setting only affects multiple lines of text relative to the text bounds. -
setTextAlignment
Sets the value of the property textAlignment.- Property description:
- Specifies the behavior for lines of text when text is multiline.
Unlike
contentDisplay
which affects the graphic and text, this setting only affects multiple lines of text relative to the text bounds.
-
getTextAlignment
Gets the value of the property textAlignment.- Property description:
- Specifies the behavior for lines of text when text is multiline.
Unlike
contentDisplay
which affects the graphic and text, this setting only affects multiple lines of text relative to the text bounds.
-
textOverrunProperty
Specifies the behavior to use if the text of theTooltip
exceeds the available space for rendering the text.- See Also:
-
setTextOverrun
Sets the value of the property textOverrun.- Property description:
- Specifies the behavior to use if the text of the
Tooltip
exceeds the available space for rendering the text.
-
getTextOverrun
Gets the value of the property textOverrun.- Property description:
- Specifies the behavior to use if the text of the
Tooltip
exceeds the available space for rendering the text.
-
wrapTextProperty
If a run of text exceeds the width of the Tooltip, then this variable indicates whether the text should wrap onto another line.- See Also:
-
setWrapText
public final void setWrapText(boolean value) Sets the value of the property wrapText.- Property description:
- If a run of text exceeds the width of the Tooltip, then this variable indicates whether the text should wrap onto another line.
-
isWrapText
public final boolean isWrapText()Gets the value of the property wrapText.- Property description:
- If a run of text exceeds the width of the Tooltip, then this variable indicates whether the text should wrap onto another line.
-
fontProperty
The default font to use for text in the Tooltip. If the Tooltip's text is rich text then this font may or may not be used depending on the font information embedded in the rich text, but in any case where a default font is required, this font will be used.- See Also:
-
setFont
Sets the value of the property font.- Property description:
- The default font to use for text in the Tooltip. If the Tooltip's text is rich text then this font may or may not be used depending on the font information embedded in the rich text, but in any case where a default font is required, this font will be used.
-
getFont
Gets the value of the property font.- Property description:
- The default font to use for text in the Tooltip. If the Tooltip's text is rich text then this font may or may not be used depending on the font information embedded in the rich text, but in any case where a default font is required, this font will be used.
-
showDelayProperty
The delay between the mouse entering the hovered node and when the associated tooltip will be shown to the user. The default delay is 1000ms.- Default value:
- 1000ms
- Since:
- 9
- See Also:
-
setShowDelay
Sets the value of the property showDelay.- Property description:
- The delay between the mouse entering the hovered node and when the associated tooltip will be shown to the user. The default delay is 1000ms.
- Default value:
- 1000ms
- Since:
- 9
-
getShowDelay
Gets the value of the property showDelay.- Property description:
- The delay between the mouse entering the hovered node and when the associated tooltip will be shown to the user. The default delay is 1000ms.
- Default value:
- 1000ms
- Since:
- 9
-
showDurationProperty
The duration that the tooltip should remain showing for until it is no longer visible to the user. If the mouse leaves the control before the showDuration finishes, then the tooltip will remain showing for the duration specified in thehideDelayProperty()
, even if the remaining time of the showDuration is less than the hideDelay duration. The default value is 5000ms.- Default value:
- 5000ms
- Since:
- 9
- See Also:
-
setShowDuration
Sets the value of the property showDuration.- Property description:
- The duration that the tooltip should remain showing for until it is no longer visible to the user.
If the mouse leaves the control before the showDuration finishes, then the tooltip will remain showing
for the duration specified in the
hideDelayProperty()
, even if the remaining time of the showDuration is less than the hideDelay duration. The default value is 5000ms. - Default value:
- 5000ms
- Since:
- 9
-
getShowDuration
Gets the value of the property showDuration.- Property description:
- The duration that the tooltip should remain showing for until it is no longer visible to the user.
If the mouse leaves the control before the showDuration finishes, then the tooltip will remain showing
for the duration specified in the
hideDelayProperty()
, even if the remaining time of the showDuration is less than the hideDelay duration. The default value is 5000ms. - Default value:
- 5000ms
- Since:
- 9
-
hideDelayProperty
The duration in which to continue showing the tooltip after the mouse has left the node. Once this time has elapsed the tooltip will hide. The default value is 200ms.- Default value:
- 200ms
- Since:
- 9
- See Also:
-
setHideDelay
Sets the value of the property hideDelay.- Property description:
- The duration in which to continue showing the tooltip after the mouse has left the node. Once this time has elapsed the tooltip will hide. The default value is 200ms.
- Default value:
- 200ms
- Since:
- 9
-
getHideDelay
Gets the value of the property hideDelay.- Property description:
- The duration in which to continue showing the tooltip after the mouse has left the node. Once this time has elapsed the tooltip will hide. The default value is 200ms.
- Default value:
- 200ms
- Since:
- 9
-
graphicProperty
An optional icon for the Tooltip. This can be positioned relative to the text by using thecontent display
property. The node specified for this variable cannot appear elsewhere in the scene graph, otherwise theIllegalArgumentException
is thrown. See the class description ofNode
for more detail.- See Also:
-
setGraphic
Sets the value of the property graphic.- Property description:
- An optional icon for the Tooltip. This can be positioned relative to the
text by using the
content display
property. The node specified for this variable cannot appear elsewhere in the scene graph, otherwise theIllegalArgumentException
is thrown. See the class description ofNode
for more detail.
-
getGraphic
Gets the value of the property graphic.- Property description:
- An optional icon for the Tooltip. This can be positioned relative to the
text by using the
content display
property. The node specified for this variable cannot appear elsewhere in the scene graph, otherwise theIllegalArgumentException
is thrown. See the class description ofNode
for more detail.
-
contentDisplayProperty
Specifies the positioning of the graphic relative to the text. -
setContentDisplay
Sets the value of the property contentDisplay.- Property description:
- Specifies the positioning of the graphic relative to the text.
-
getContentDisplay
Gets the value of the property contentDisplay.- Property description:
- Specifies the positioning of the graphic relative to the text.
-
graphicTextGapProperty
The amount of space between the graphic and text- See Also:
-
setGraphicTextGap
public final void setGraphicTextGap(double value) Sets the value of the property graphicTextGap.- Property description:
- The amount of space between the graphic and text
-
getGraphicTextGap
public final double getGraphicTextGap()Gets the value of the property graphicTextGap.- Property description:
- The amount of space between the graphic and text
-
isActivated
public final boolean isActivated()Gets the value of the property activated.- Property description:
- Typically, the tooltip is "activated" when the mouse moves over a Control. There is usually some delay between when the Tooltip becomes "activated" and when it is actually shown. The details (such as the amount of delay, etc) is left to the Skin implementation.
-
activatedProperty
Typically, the tooltip is "activated" when the mouse moves over a Control. There is usually some delay between when the Tooltip becomes "activated" and when it is actually shown. The details (such as the amount of delay, etc) is left to the Skin implementation.- See Also:
-
getClassCssMetaData
Gets theCssMetaData
associated with this class, which may include theCssMetaData
of its superclasses.- Returns:
- the
CssMetaData
- Since:
- JavaFX 8.0
-
getCssMetaData
The CssMetaData of this Styleable. This may be returned as an unmodifiable list.- Specified by:
getCssMetaData
in interfaceStyleable
- Overrides:
getCssMetaData
in classPopupControl
- Returns:
- the CssMetaData
- Since:
- JavaFX 8.0
-