Top Description Inners Fields Constructors Methods
javafx.scene.control

public Class Tooltip

extends PopupControl
Class Inheritance
Annotations
@IDProperty:id
Imports
com.sun.javafx.beans.IDProperty, com.sun.javafx.css.StyleManager, com.sun.javafx.scene.NodeHelper, com.sun.javafx.stage.PopupWindowHelper, javafx.css.SimpleStyleableBooleanProperty, .SimpleStyleableDoubleProperty, .SimpleStyleableObjectProperty, .StyleOrigin, .StyleableObjectProperty, .StyleableStringProperty, .CssMetaData, .FontCssMetaData, .Styleable, .StyleableProperty, javafx.css.converter.BooleanConverter, .EnumConverter, .SizeConverter, .StringConverter, .DurationConverter, javafx.scene.control.skin.TooltipSkin, java.util.ArrayList, .Collections, .List, javafx.animation.KeyFrame, .Timeline, javafx.beans.property.*, javafx.beans.value.WritableValue, javafx.event.EventHandler, javafx.geometry.NodeOrientation, javafx.scene.AccessibleRole, .Node, .Parent, .Scene, javafx.scene.image.Image, .ImageView, javafx.scene.input.MouseEvent, javafx.scene.text.Font, .TextAlignment, javafx.stage.Window, javafx.util.Duration

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"));
Image of the Tooltip control
Since
JavaFX 2.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private static class

Field Summary

Modifier and TypeField and Description
private final ReadOnlyBooleanWrapper
activated

Typically, the tooltip is "activated" when the mouse moves over a Control.

private static Tooltip.TooltipBehavior
private static final CssMetaData<Tooltip.CSSBridge, ContentDisplay>
private final ObjectProperty<ContentDisplay>
private final ObjectProperty<Font>
private static final CssMetaData<Tooltip.CSSBridge, Font>
private final ObjectProperty<Node>
private static final CssMetaData<Tooltip.CSSBridge, String>
private static final CssMetaData<Tooltip.CSSBridge, Number>
private final DoubleProperty
private static final CssMetaData<Tooltip.CSSBridge, Duration>
private final ObjectProperty<Duration>
private StyleableStringProperty
private static final CssMetaData<Tooltip.CSSBridge, Duration>
private static final CssMetaData<Tooltip.CSSBridge, Duration>
private final ObjectProperty<Duration>
private final ObjectProperty<Duration>
private static final List<CssMetaData<? extends Styleable, ?>>
private final StringProperty
private static final CssMetaData<Tooltip.CSSBridge, TextAlignment>
private static final CssMetaData<Tooltip.CSSBridge, OverrunStyle>
private final ObjectProperty<TextAlignment>
private final ObjectProperty<OverrunStyle>
private static String
private static int
private static int
private static final CssMetaData<Tooltip.CSSBridge, Boolean>
private final BooleanProperty
Inherited from javafx.scene.control.PopupControl:
bridgeUSE_COMPUTED_SIZEUSE_PREF_SIZE

Constructor Summary

AccessConstructor and Description
public
Tooltip()

Creates a tooltip with an empty string for its text.

public
Tooltip(String
A text string for the tooltip.
text
)

Creates a tooltip with the specified text.

Method Summary

Modifier and TypeMethod and Description
public final ReadOnlyBooleanProperty
public final ObjectProperty<ContentDisplay>

Returns:

the content display property
contentDisplayProperty
()

Specifies the positioning of the graphic relative to the text.

protected Skin<?>
createDefaultSkin()

Overrides javafx.scene.control.PopupControl.createDefaultSkin.

Create a new instance of the default skin for this control.

public final ObjectProperty<Font>

Returns:

the font property
fontProperty
()

The default font to use for text in the Tooltip.

public static List<CssMetaData<? extends Styleable, ?>>

Returns:

the CssMetaData
getClassCssMetaData
()

Hides javafx.scene.control.PopupControl.getClassCssMetaData.

Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.

public final ContentDisplay
public List<CssMetaData<? extends Styleable, ?>>
public final Font
public final Node
public final double
public final Duration
public final Duration
public final Duration
public Styleable
getStyleableParent()

Overrides javafx.scene.control.PopupControl.getStyleableParent.

Implements javafx.css.Styleable.getStyleableParent.

Return the parent of this Styleable, or null if there is no parent.

public final String
public final TextAlignment
public final OverrunStyle
public final ObjectProperty<Node>

Returns:

the graphic property
graphicProperty
()

An optional icon for the Tooltip.

public final DoubleProperty

Returns:

the graphic text gap property
graphicTextGapProperty
()

The amount of space between the graphic and text

public final ObjectProperty<Duration>

Returns:

the hide delay property
hideDelayProperty
()

The duration in which to continue showing the tooltip after the mouse has left the node.

private StyleableStringProperty
public static void
install(Node
the node
node
,
Tooltip
the tooltip
t
)

Associates the given Tooltip with the given Node.

public final boolean
public final boolean
pack-priv final void
setActivated(boolean value)

public final void
public final void
setFont(Font value)

public final void
public final void
setGraphicTextGap(double value)

public final void
public final void
public final void
setShowDuration(Duration showDuration)

public final void
setText(String value)

public final void
public final void
public final void
setWrapText(boolean value)

public final ObjectProperty<Duration>

Returns:

show delay property
showDelayProperty
()

The delay between the mouse entering the hovered node and when the associated tooltip will be shown to the user.

public final ObjectProperty<Duration>

Returns:

the show duration property
showDurationProperty
()

The duration that the tooltip should remain showing for until it is no longer visible to the user.

public final ObjectProperty<TextAlignment>

Returns:

the text alignment property
textAlignmentProperty
()

Specifies the behavior for lines of text when text is multiline.

public final ObjectProperty<OverrunStyle>

Returns:

the text overrun property
textOverrunProperty
()

Specifies the behavior to use if the text of the Tooltip exceeds the available space for rendering the text.

public final StringProperty

Returns:

the text property
textProperty
()

The text to display in the tooltip.

public static void
uninstall(Node
the node
node
,
Tooltip
the tooltip
t
)

Removes the association of the given Tooltip on the specified Node.

public final BooleanProperty

Returns:

the wrap text property
wrapTextProperty
()

If a run of text exceeds the width of the Tooltip, then this variable indicates whether the text should wrap onto another line.

Inherited from javafx.scene.control.PopupControl:
getIdgetMaxHeightgetMaxWidthgetMinHeightgetMinWidthgetPrefHeightgetPrefWidthgetPseudoClassStatesgetSkingetStylegetStyleableNodegetStyleClassgetTypeSelectoridPropertymaxHeightmaxHeightPropertymaxWidthmaxWidthPropertyminHeightminHeightPropertyminWidthminWidthPropertyprefHeightprefHeightPropertyprefWidthprefWidthPropertypseudoClassStateChangedsetIdsetMaxHeightsetMaxSizesetMaxWidthsetMinHeightsetMinSizesetMinWidthsetPrefHeightsetPrefSizesetPrefWidthsetSkinsetStyleskinPropertystyleProperty

Field Detail

activatedback to summary
private final ReadOnlyBooleanWrapper 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.

BEHAVIORback to summary
private static Tooltip.TooltipBehavior BEHAVIOR
CONTENT_DISPLAYback to summary
private static final CssMetaData<Tooltip.CSSBridge, ContentDisplay> CONTENT_DISPLAY
contentDisplayback to summary
private final ObjectProperty<ContentDisplay> contentDisplay
fontback to summary
private final ObjectProperty<Font> font
FONTback to summary
private static final CssMetaData<Tooltip.CSSBridge, Font> FONT
graphicback to summary
private final ObjectProperty<Node> graphic
GRAPHICback to summary
private static final CssMetaData<Tooltip.CSSBridge, String> GRAPHIC
GRAPHIC_TEXT_GAPback to summary
private static final CssMetaData<Tooltip.CSSBridge, Number> GRAPHIC_TEXT_GAP
graphicTextGapback to summary
private final DoubleProperty graphicTextGap
HIDE_DELAYback to summary
private static final CssMetaData<Tooltip.CSSBridge, Duration> HIDE_DELAY
hideDelayPropertyback to summary
private final ObjectProperty<Duration> hideDelayProperty
imageUrlback to summary
private StyleableStringProperty imageUrl
SHOW_DELAYback to summary
private static final CssMetaData<Tooltip.CSSBridge, Duration> SHOW_DELAY
SHOW_DURATIONback to summary
private static final CssMetaData<Tooltip.CSSBridge, Duration> SHOW_DURATION
showDelayPropertyback to summary
private final ObjectProperty<Duration> showDelayProperty
showDurationPropertyback to summary
private final ObjectProperty<Duration> showDurationProperty
STYLEABLESback to summary
private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES

Hides javafx.scene.control.PopupControl.STYLEABLES.

textback to summary
private final StringProperty text
TEXT_ALIGNMENTback to summary
private static final CssMetaData<Tooltip.CSSBridge, TextAlignment> TEXT_ALIGNMENT
TEXT_OVERRUNback to summary
private static final CssMetaData<Tooltip.CSSBridge, OverrunStyle> TEXT_OVERRUN
textAlignmentback to summary
private final ObjectProperty<TextAlignment> textAlignment
textOverrunback to summary
private final ObjectProperty<OverrunStyle> textOverrun
TOOLTIP_PROP_KEYback to summary
private static String TOOLTIP_PROP_KEY
TOOLTIP_XOFFSETback to summary
private static int TOOLTIP_XOFFSET
TOOLTIP_YOFFSETback to summary
private static int TOOLTIP_YOFFSET
WRAP_TEXTback to summary
private static final CssMetaData<Tooltip.CSSBridge, Boolean> WRAP_TEXT
wrapTextback to summary
private final BooleanProperty wrapText

Constructor Detail

Tooltipback to summary
public Tooltip()

Creates a tooltip with an empty string for its text.

Tooltipback to summary
public Tooltip(String text)

Creates a tooltip with the specified text.

Parameters
text:String

A text string for the tooltip.

Method Detail

activatedPropertyback to summary
public final ReadOnlyBooleanProperty activatedProperty()
contentDisplayPropertyback to summary
public final ObjectProperty<ContentDisplay> contentDisplayProperty()

Specifies the positioning of the graphic relative to the text.

Returns:ObjectProperty<ContentDisplay>

the content display property

createDefaultSkinback to summary
protected Skin<?> createDefaultSkin()

Overrides javafx.scene.control.PopupControl.createDefaultSkin.

Doc from javafx.scene.control.PopupControl.createDefaultSkin.

Create a new instance of the default skin for this control. This is called to create a skin for the control if no skin is provided via CSS -fx-skin or set explicitly in a sub-class with setSkin(...).

Returns:Skin<?>

new instance of default skin for this control. If null then the control will have no skin unless one is provided by css.

Annotations
@Override
fontPropertyback to summary
public final ObjectProperty<Font> 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.

Returns:ObjectProperty<Font>

the font property

getClassCssMetaDataback to summary
public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData()

Hides javafx.scene.control.PopupControl.getClassCssMetaData.

Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.

Returns:List<CssMetaData<? extends Styleable, ?>>

the CssMetaData

Since
JavaFX 8.0
getContentDisplayback to summary
public final ContentDisplay getContentDisplay()
getCssMetaDataback to summary
public List<CssMetaData<? extends Styleable, ?>> getCssMetaData()

Overrides javafx.scene.control.PopupControl.getCssMetaData.

Implements javafx.css.Styleable.getCssMetaData.

Doc from javafx.scene.control.PopupControl.getCssMetaData.

The CssMetaData of this Styleable. This may be returned as an unmodifiable list.

Returns:List<CssMetaData<? extends Styleable, ?>>

Doc from javafx.css.Styleable.getCssMetaData.

the CssMetaData

Annotations
@Override
Since
JavaFX 8.0
getFontback to summary
public final Font getFont()
getGraphicback to summary
public final Node getGraphic()
getGraphicTextGapback to summary
public final double getGraphicTextGap()
getHideDelayback to summary
public final Duration getHideDelay()
getShowDelayback to summary
public final Duration getShowDelay()
getShowDurationback to summary
public final Duration getShowDuration()
getStyleableParentback to summary
public Styleable getStyleableParent()

Overrides javafx.scene.control.PopupControl.getStyleableParent.

Implements javafx.css.Styleable.getStyleableParent.

Doc from javafx.scene.control.PopupControl.getStyleableParent.

Return the parent of this Styleable, or null if there is no parent. A PopupControl's styles are based on the popup "owner" which is the ownerNode or, if the ownerNode is not set, the root of the ownerWindow's scene. If the popup has not been shown, both ownerNode and ownerWindow will be null and null will be returned. Note that the PopupWindow's scene root is not returned because there is no way to guarantee that the PopupWindow's scene root would properly return the ownerNode or ownerWindow.

Returns:Styleable

javafx.stage.PopupWindow#getOwnerNode(), javafx.stage.PopupWindow#getOwnerWindow(), or null.

Annotations
@Override
getTextback to summary
public final String getText()
getTextAlignmentback to summary
public final TextAlignment getTextAlignment()
getTextOverrunback to summary
public final OverrunStyle getTextOverrun()
graphicPropertyback to summary
public final ObjectProperty<Node> graphicProperty()

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 the IllegalArgumentException is thrown. See the class description of Node for more detail.

Returns:ObjectProperty<Node>

the graphic property

graphicTextGapPropertyback to summary
public final DoubleProperty graphicTextGapProperty()

The amount of space between the graphic and text

Returns:DoubleProperty

the graphic text gap property

hideDelayPropertyback to summary
public final ObjectProperty<Duration> 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.

Returns:ObjectProperty<Duration>

the hide delay property

Default Value
200ms
Since
9
imageUrlPropertyback to summary
private StyleableStringProperty imageUrlProperty()
installback to summary
public static void install(Node node, Tooltip t)

Associates the given Tooltip with the given Node. The tooltip can then behave similar to when it is set on any Control. A single tooltip can be associated with multiple nodes.

Parameters
node:Node

the node

t:Tooltip

the tooltip

See Also
Tooltip
isActivatedback to summary
public final boolean isActivated()
isWrapTextback to summary
public final boolean isWrapText()
setActivatedback to summary
pack-priv final void setActivated(boolean value)
setContentDisplayback to summary
public final void setContentDisplay(ContentDisplay value)
setFontback to summary
public final void setFont(Font value)
setGraphicback to summary
public final void setGraphic(Node value)
setGraphicTextGapback to summary
public final void setGraphicTextGap(double value)
setHideDelayback to summary
public final void setHideDelay(Duration hideDelay)
setShowDelayback to summary
public final void setShowDelay(Duration showDelay)
setShowDurationback to summary
public final void setShowDuration(Duration showDuration)
setTextback to summary
public final void setText(String value)
setTextAlignmentback to summary
public final void setTextAlignment(TextAlignment value)
setTextOverrunback to summary
public final void setTextOverrun(OverrunStyle value)
setWrapTextback to summary
public final void setWrapText(boolean value)
showDelayPropertyback to summary
public final ObjectProperty<Duration> 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.

Returns:ObjectProperty<Duration>

show delay property

Default Value
1000ms
Since
9
showDurationPropertyback to summary
public final ObjectProperty<Duration> 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 the hideDelayProperty(), even if the remaining time of the showDuration is less than the hideDelay duration. The default value is 5000ms.

Returns:ObjectProperty<Duration>

the show duration property

Default Value
5000ms
Since
9
textAlignmentPropertyback to summary
public final ObjectProperty<TextAlignment> textAlignmentProperty()

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.

Returns:ObjectProperty<TextAlignment>

the text alignment property

textOverrunPropertyback to summary
public final ObjectProperty<OverrunStyle> textOverrunProperty()

Specifies the behavior to use if the text of the Tooltip exceeds the available space for rendering the text.

Returns:ObjectProperty<OverrunStyle>

the text overrun property

textPropertyback to summary
public final StringProperty 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.

Returns:StringProperty

the text property

uninstallback to summary
public static void uninstall(Node node, Tooltip t)

Removes the association of the given Tooltip on the specified Node. Hence hovering on the node will no longer result in showing of the tooltip.

Parameters
node:Node

the node

t:Tooltip

the tooltip

See Also
Tooltip
wrapTextPropertyback to summary
public final BooleanProperty wrapTextProperty()

If a run of text exceeds the width of the Tooltip, then this variable indicates whether the text should wrap onto another line.

Returns:BooleanProperty

the wrap text property

javafx.scene.control back to summary

private final Class Tooltip.CSSBridge

extends CSSBridge
Class Inheritance

Field Summary

Modifier and TypeField and Description
private Tooltip

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Inherited from javafx.scene.control.PopupControl.CSSBridge:
getCssMetaDatagetStyleableParentrequestLayout

Field Detail

tooltipback to summary
private Tooltip tooltip

Constructor Detail

CSSBridgeback to summary
pack-priv CSSBridge()
javafx.scene.control back to summary

private Class Tooltip.TooltipBehavior

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private Tooltip
activatedTooltip

The tooltip that is currently activated.

private Timeline
private boolean
private Timeline
private Node
hoveredNode

The Node with a tooltip over which the mouse is hovering.

private EventHandler<MouseEvent>
KILL_HANDLER

Registers for mouse click, press, release, drag events.

private double
lastMouseX

The last position of the mouse, in screen coordinates.

private double
private EventHandler<MouseEvent>
LEAVING_HANDLER

Registers for mouse exit events.

private Timeline
private EventHandler<MouseEvent>
MOVE_HANDLER

Registers for mouse move events only.

private Tooltip
visibleTooltip

The tooltip that is currently visible.

Constructor Summary

AccessConstructor and Description
pack-priv
TooltipBehavior(final boolean hideOnExit)

Method Summary

Modifier and TypeMethod and Description
private Window

Returns:

the top level window
getWindow
(final Node
the node
node
)

Gets the top level window associated with this node.

private void
install(Node node, Tooltip t)

private boolean

Returns:

true if entire hierarchy is visible
isWindowHierarchyVisible
(Node
the node to check
node
)

Gets whether the entire window hierarchy is visible for this node.

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

activatedTooltipback to summary
private Tooltip activatedTooltip

The tooltip that is currently activated. There can only be one of these at a time.

activationTimerback to summary
private Timeline activationTimer
hideOnExitback to summary
private boolean hideOnExit
hideTimerback to summary
private Timeline hideTimer
hoveredNodeback to summary
private Node hoveredNode

The Node with a tooltip over which the mouse is hovering. There can only be one of these at a time.

KILL_HANDLERback to summary
private EventHandler<MouseEvent> KILL_HANDLER

Registers for mouse click, press, release, drag events. If any of these occur, then the tooltip is hidden (if it is visible), it is deactivated, and any and all timers are stopped.

lastMouseXback to summary
private double lastMouseX

The last position of the mouse, in screen coordinates.

lastMouseYback to summary
private double lastMouseY
LEAVING_HANDLERback to summary
private EventHandler<MouseEvent> LEAVING_HANDLER

Registers for mouse exit events. If the ACTIVATION_TIMER is running then this will simply stop it. If the HIDE_TIMER is running then this will stop the HIDE_TIMER, hide the tooltip, and start the LEFT_TIMER.

leftTimerback to summary
private Timeline leftTimer
MOVE_HANDLERback to summary
private EventHandler<MouseEvent> MOVE_HANDLER

Registers for mouse move events only. When the mouse is moved, this handler will detect it and decide whether to start the ACTIVATION_TIMER (if the ACTIVATION_TIMER is not started), restart the ACTIVATION_TIMER (if ACTIVATION_TIMER is running), or skip the ACTIVATION_TIMER and just show the tooltip (if the LEFT_TIMER is running).

visibleTooltipback to summary
private Tooltip visibleTooltip

The tooltip that is currently visible. There can only be one of these at a time.

Constructor Detail

TooltipBehaviorback to summary
pack-priv TooltipBehavior(final boolean hideOnExit)

Method Detail

getWindowback to summary
private Window getWindow(final Node node)

Gets the top level window associated with this node.

Parameters
node:Node

the node

Returns:Window

the top level window

installback to summary
private void install(Node node, Tooltip t)
isWindowHierarchyVisibleback to summary
private boolean isWindowHierarchyVisible(Node node)

Gets whether the entire window hierarchy is visible for this node.

Parameters
node:Node

the node to check

Returns:boolean

true if entire hierarchy is visible

uninstallback to summary
private void uninstall(Node node)