Spec-Zone.ru › OpenJavaFX 8
javafx.scene.control

Class Tooltip

java.lang.Object
  • javafx.stage.Window
    • javafx.stage.PopupWindow
      • javafx.scene.control.PopupControl
        • javafx.scene.control.Tooltip

All Implemented Interfaces:

Styleable, EventTarget, Skinnable



@IDProperty(value="id")
public class Tooltip
extends PopupControl
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:

import javafx.scene.control.Tooltip;
 import javafx.scene.control.Button;

 Button button = new Button("Hover Over Me");
 button.setTooltip(new Tooltip("Tooltip for Button"));

Since:

JavaFX 2.0

  • Property Summary

    All MethodsInstance MethodsConcrete Methods
    Type Property and Description
    ReadOnlyBooleanProperty activated
    Typically, the tooltip is "activated" when the mouse moves over a Control.
    ObjectProperty<ContentDisplay> contentDisplay
    Specifies the positioning of the graphic relative to the text.
    ObjectProperty<Font> font
    The default font to use for text in the Tooltip.
    ObjectProperty<Node> graphic
    An optional icon for the Tooltip.
    DoubleProperty graphicTextGap
    The amount of space between the graphic and text
    ObjectProperty<TextAlignment> textAlignment
    Specifies the behavior for lines of text when text is multiline.
    ObjectProperty<OverrunStyle> textOverrun
    Specifies the behavior to use if the text of the Tooltip exceeds the available space for rendering the text.
    StringProperty text
    The text to display in the tooltip.
    BooleanProperty wrapText
    If a run of text exceeds the width of the Tooltip, then this variable indicates whether the text should wrap onto another line.
    • Properties inherited from class javafx.scene.control.PopupControl

      id, maxHeight, maxWidth, minHeight, minWidth, prefHeight, prefWidth, skin, style
    • Properties inherited from class javafx.stage.PopupWindow

      anchorLocation, anchorX, anchorY, autoFix, autoHide, consumeAutoHidingEvents, hideOnEscape, onAutoHide, ownerNode, ownerWindow
    • Properties inherited from class javafx.stage.Window

      eventDispatcher, focused, height, onCloseRequest, onHidden, onHiding, onShowing, onShown, opacity, scene, showing, width, x, y
  • Nested Class Summary

    • Nested classes/interfaces inherited from class javafx.stage.PopupWindow

      PopupWindow.AnchorLocation
  • Field Summary

    • Fields inherited from class javafx.scene.control.PopupControl

      bridge, USE_COMPUTED_SIZE, USE_PREF_SIZE
  • Constructor Summary

    Constructors
    Constructor and Description
    Tooltip()
    Creates a tooltip with an empty string for its text.
    Tooltip(String text)
    Creates a tooltip with the specified text.
  • Method Summary

    All MethodsStatic MethodsInstance MethodsConcrete Methods
    Modifier and Type Method and Description
    ReadOnlyBooleanProperty activatedProperty()
    Typically, the tooltip is "activated" when the mouse moves over a Control.
    ObjectProperty<ContentDisplay> contentDisplayProperty()
    Specifies the positioning of the graphic relative to the text.
    protected Skin<?> createDefaultSkin()
    Create a new instance of the default skin for this control.
    ObjectProperty<Font> fontProperty()
    The default font to use for text in the Tooltip.
    static List<CssMetaData<? extends Styleable,?>> getClassCssMetaData()
    ContentDisplay getContentDisplay()
    Gets the value of the property contentDisplay.
    List<CssMetaData<? extends Styleable,?>> getCssMetaData()
    The CssMetaData of this Styleable.
    Font getFont()
    Gets the value of the property font.
    Node getGraphic()
    Gets the value of the property graphic.
    double getGraphicTextGap()
    Gets the value of the property graphicTextGap.
    Styleable getStyleableParent()
    Return the parent of this Styleable, or null if there is no parent.
    String getText()
    Gets the value of the property text.
    TextAlignment getTextAlignment()
    Gets the value of the property textAlignment.
    OverrunStyle getTextOverrun()
    Gets the value of the property textOverrun.
    ObjectProperty<Node> graphicProperty()
    An optional icon for the Tooltip.
    DoubleProperty graphicTextGapProperty()
    The amount of space between the graphic and text
    static void install(Node node, Tooltip t)
    Associates the given Tooltip with the given Node.
    boolean isActivated()
    Gets the value of the property activated.
    boolean isWrapText()
    Gets the value of the property wrapText.
    void setContentDisplay(ContentDisplay value)
    Sets the value of the property contentDisplay.
    void setFont(Font value)
    Sets the value of the property font.
    void setGraphic(Node value)
    Sets the value of the property graphic.
    void setGraphicTextGap(double value)
    Sets the value of the property graphicTextGap.
    void setText(String value)
    Sets the value of the property text.
    void setTextAlignment(TextAlignment value)
    Sets the value of the property textAlignment.
    void setTextOverrun(OverrunStyle value)
    Sets the value of the property textOverrun.
    void setWrapText(boolean value)
    Sets the value of the property wrapText.
    ObjectProperty<TextAlignment> textAlignmentProperty()
    Specifies the behavior for lines of text when text is multiline.
    ObjectProperty<OverrunStyle> textOverrunProperty()
    Specifies the behavior to use if the text of the Tooltip exceeds the available space for rendering the text.
    StringProperty textProperty()
    The text to display in the tooltip.
    static void uninstall(Node node, Tooltip t)
    Removes the association of the given Tooltip on the specified Node.
    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.
    • Methods inherited from class javafx.scene.control.PopupControl

      getId, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getPrefHeight, getPrefWidth, getPseudoClassStates, getSkin, getStyle, 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 inherited from 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 inherited from class javafx.stage.Window

      addEventFilter, addEventHandler, buildEventDispatchChain, centerOnScreen, eventDispatcherProperty, fireEvent, focusedProperty, getEventDispatcher, getHeight, getOnCloseRequest, getOnHidden, getOnHiding, getOnShowing, getOnShown, getOpacity, getProperties, getScene, getUserData, getWidth, getX, getY, hasProperties, heightProperty, isFocused, isShowing, onCloseRequestProperty, onHiddenProperty, onHidingProperty, onShowingProperty, onShownProperty, opacityProperty, removeEventFilter, removeEventHandler, requestFocus, sceneProperty, setEventDispatcher, setEventHandler, setHeight, setOnCloseRequest, setOnHidden, setOnHiding, setOnShowing, setOnShown, setOpacity, setUserData, setWidth, setX, setY, show, showingProperty, sizeToScene, widthProperty, xProperty, yProperty
    • Methods inherited from class java.lang.Object

      clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Property Detail

    • text

      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.

      See Also:

      getText(), setText(String)

    • textAlignment

      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.

      See Also:

      getTextAlignment(), setTextAlignment(TextAlignment)

    • textOverrun

      public final ObjectProperty<OverrunStyle> textOverrunProperty
      Specifies the behavior to use if the text of the Tooltip exceeds the available space for rendering the text.

      See Also:

      getTextOverrun(), setTextOverrun(OverrunStyle)

    • wrapText

      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.

      See Also:

      isWrapText(), setWrapText(boolean)

    • font

      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.

      See Also:

      getFont(), setFont(Font)

    • graphic

      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.

      See Also:

      getGraphic(), setGraphic(Node)

    • contentDisplay

      public final ObjectProperty<ContentDisplay> contentDisplayProperty
      Specifies the positioning of the graphic relative to the text.

      See Also:

      getContentDisplay(), setContentDisplay(ContentDisplay)

    • graphicTextGap

      public final DoubleProperty graphicTextGapProperty
      The amount of space between the graphic and text

      See Also:

      getGraphicTextGap(), setGraphicTextGap(double)

    • activated

      public final ReadOnlyBooleanProperty 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:

      isActivated()

  • Constructor Detail

    • Tooltip

      public Tooltip()
      Creates a tooltip with an empty string for its text.
    • Tooltip

      public Tooltip(String text)
      Creates a tooltip with the specified text.

      Parameters:

      text - A text string for the tooltip.

  • Method Detail

    • install

      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.

      See Also:

      Tooltip

    • uninstall

      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.

      See Also:

      Tooltip

    • textProperty

      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.

      See Also:

      getText(), setText(String)

    • setText

      public final void setText(String value)
      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

      public final String 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

      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.

      See Also:

      getTextAlignment(), setTextAlignment(TextAlignment)

    • setTextAlignment

      public final void setTextAlignment(TextAlignment value)
      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

      public final TextAlignment 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

      public final ObjectProperty<OverrunStyle> textOverrunProperty()
      Specifies the behavior to use if the text of the Tooltip exceeds the available space for rendering the text.

      See Also:

      getTextOverrun(), setTextOverrun(OverrunStyle)

    • setTextOverrun

      public final void setTextOverrun(OverrunStyle value)
      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

      public final OverrunStyle 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

      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.

      See Also:

      isWrapText(), setWrapText(boolean)

    • 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

      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.

      See Also:

      getFont(), setFont(Font)

    • setFont

      public final void setFont(Font value)
      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

      public final Font 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.

    • graphicProperty

      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.

      See Also:

      getGraphic(), setGraphic(Node)

    • setGraphic

      public final void setGraphic(Node value)
      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 the IllegalArgumentException is thrown. See the class description of Node for more detail.

    • getGraphic

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

    • contentDisplayProperty

      public final ObjectProperty<ContentDisplay> contentDisplayProperty()
      Specifies the positioning of the graphic relative to the text.

      See Also:

      getContentDisplay(), setContentDisplay(ContentDisplay)

    • setContentDisplay

      public final void setContentDisplay(ContentDisplay value)
      Sets the value of the property contentDisplay.

      Property description:

      Specifies the positioning of the graphic relative to the text.

    • getContentDisplay

      public final ContentDisplay getContentDisplay()
      Gets the value of the property contentDisplay.

      Property description:

      Specifies the positioning of the graphic relative to the text.

    • graphicTextGapProperty

      public final DoubleProperty graphicTextGapProperty()
      The amount of space between the graphic and text

      See Also:

      getGraphicTextGap(), setGraphicTextGap(double)

    • 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

      public final ReadOnlyBooleanProperty 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:

      isActivated()

    • createDefaultSkin

      protected Skin<?> 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(...).

      Overrides:

      createDefaultSkin in class PopupControl

      Returns:

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

    • getClassCssMetaData

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

      Returns:

      The CssMetaData associated with this class, which may include the CssMetaData of its super classes.

      Since:

      JavaFX 8.0

    • getCssMetaData

      public List<CssMetaData<? extends Styleable,?>> getCssMetaData()
      The CssMetaData of this Styleable. This may be returned as an unmodifiable list.

      Specified by:

      getCssMetaData in interface Styleable

      Overrides:

      getCssMetaData in class PopupControl

      Since:

      JavaFX 8.0

    • getStyleableParent

      public Styleable getStyleableParent()
      Description copied from class: PopupControl
      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.

      Specified by:

      getStyleableParent in interface Styleable

      Overrides:

      getStyleableParent in class PopupControl

      Returns:

      PopupWindow.getOwnerNode(), PopupWindow.getOwnerWindow(), or null.

© 2008, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from JavaFX API Documentation.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Java, JavaFX and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API