@IDProperty(value="id") public class Tooltip extends PopupControl
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"));
Modifier and Type | Class and Description |
---|---|
private class |
Tooltip.CSSBridge
*
Support classes *
*
|
private static class |
Tooltip.TooltipBehavior |
PopupWindow.AnchorLocation
bridge, USE_COMPUTED_SIZE, USE_PREF_SIZE
impl_peer, peerListener
Constructor and Description |
---|
Tooltip()
Creates a tooltip with an empty string for its text.
|
Tooltip(java.lang.String text)
Creates a tooltip with the specified text.
|
Modifier and Type | Method and Description |
---|---|
ReadOnlyBooleanProperty |
activatedProperty() |
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 java.util.List<CssMetaData<? extends Styleable,?>> |
getClassCssMetaData() |
ContentDisplay |
getContentDisplay() |
java.util.List<CssMetaData<? extends Styleable,?>> |
getCssMetaData()
The CssMetaData of this Styleable.
|
Font |
getFont() |
Node |
getGraphic() |
double |
getGraphicTextGap() |
Styleable |
getStyleableParent()
Return the parent of this Styleable, or null if there is no parent.
|
java.lang.String |
getText() |
TextAlignment |
getTextAlignment() |
OverrunStyle |
getTextOverrun() |
ObjectProperty<Node> |
graphicProperty()
An optional icon for the Tooltip.
|
DoubleProperty |
graphicTextGapProperty()
The amount of space between the graphic and text
|
private StyleableStringProperty |
imageUrlProperty() |
static void |
install(Node node,
Tooltip t)
|
boolean |
isActivated() |
boolean |
isWrapText() |
(package private) void |
setActivated(boolean value) |
void |
setContentDisplay(ContentDisplay value) |
void |
setFont(Font value) |
void |
setGraphic(Node value) |
void |
setGraphicTextGap(double value) |
void |
setText(java.lang.String value) |
void |
setTextAlignment(TextAlignment value) |
void |
setTextOverrun(OverrunStyle value) |
void |
setWrapText(boolean value) |
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)
|
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.
|
getId, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getPrefHeight, getPrefWidth, getPseudoClassStates, getSkin, getStyle, getStyleClass, getTypeSelector, idProperty, impl_styleableGetNode, 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
anchorLocationProperty, anchorXProperty, anchorYProperty, autoFixProperty, autoHideProperty, consumeAutoHidingEventsProperty, getAnchorLocation, getAnchorX, getAnchorY, getConsumeAutoHidingEvents, getContent, getOnAutoHide, getOwnerNode, getOwnerWindow, hide, hideOnEscapeProperty, impl_visibleChanged, impl_visibleChanging, isAutoFix, isAutoHide, isHideOnEscape, onAutoHideProperty, ownerNodeProperty, ownerWindowProperty, setAnchorLocation, setAnchorX, setAnchorY, setAutoFix, setAutoHide, setConsumeAutoHidingEvents, setHideOnEscape, setOnAutoHide, setScene, show, show, show
addEventFilter, addEventHandler, buildEventDispatchChain, centerOnScreen, eventDispatcherProperty, fireEvent, focusedProperty, getEventDispatcher, getHeight, getOnCloseRequest, getOnHidden, getOnHiding, getOnShowing, getOnShown, getOpacity, getProperties, getScene, getUserData, getWidth, getX, getY, hasProperties, heightProperty, impl_getMXWindowType, impl_getPeer, impl_getWindows, isFocused, isShowing, onCloseRequestProperty, onHiddenProperty, onHidingProperty, onShowingProperty, onShownProperty, opacityProperty, removeEventFilter, removeEventHandler, requestFocus, sceneProperty, setEventDispatcher, setEventHandler, setFocused, setHeight, setOnCloseRequest, setOnHidden, setOnHiding, setOnShowing, setOnShown, setOpacity, setUserData, setWidth, setX, setY, show, showingProperty, sizeToScene, widthProperty, xProperty, yProperty
private static java.lang.String TOOLTIP_PROP_KEY
private static int TOOLTIP_XOFFSET
private static int TOOLTIP_YOFFSET
private static Tooltip.TooltipBehavior BEHAVIOR
private final StringProperty text
private final ObjectProperty<TextAlignment> textAlignment
private final ObjectProperty<OverrunStyle> textOverrun
private final BooleanProperty wrapText
private final ObjectProperty<Font> font
private final ObjectProperty<Node> graphic
private StyleableStringProperty imageUrl
private final ObjectProperty<ContentDisplay> contentDisplay
private final DoubleProperty graphicTextGap
private final ReadOnlyBooleanWrapper activated
private static final CssMetaData<Tooltip.CSSBridge,Font> FONT
private static final CssMetaData<Tooltip.CSSBridge,TextAlignment> TEXT_ALIGNMENT
private static final CssMetaData<Tooltip.CSSBridge,OverrunStyle> TEXT_OVERRUN
private static final CssMetaData<Tooltip.CSSBridge,java.lang.Boolean> WRAP_TEXT
private static final CssMetaData<Tooltip.CSSBridge,java.lang.String> GRAPHIC
private static final CssMetaData<Tooltip.CSSBridge,ContentDisplay> CONTENT_DISPLAY
private static final CssMetaData<Tooltip.CSSBridge,java.lang.Number> GRAPHIC_TEXT_GAP
private static final java.util.List<CssMetaData<? extends Styleable,?>> STYLEABLES
public Tooltip()
public Tooltip(java.lang.String text)
text
- A text string for the tooltip.public static void install(Node node, Tooltip t)
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.Tooltip
public static void uninstall(Node node, Tooltip t)
Tooltip
on the specified
Node
. Hence hovering on the node will no longer result in showing of the
tooltip.Tooltip
public final StringProperty textProperty()
public final void setText(java.lang.String value)
public final java.lang.String getText()
public final ObjectProperty<TextAlignment> textAlignmentProperty()
contentDisplay
which affects the
graphic and text, this setting only affects multiple lines of text
relative to the text bounds.public final void setTextAlignment(TextAlignment value)
public final TextAlignment getTextAlignment()
public final ObjectProperty<OverrunStyle> textOverrunProperty()
Tooltip
exceeds the available space for rendering the text.public final void setTextOverrun(OverrunStyle value)
public final OverrunStyle getTextOverrun()
public final BooleanProperty wrapTextProperty()
public final void setWrapText(boolean value)
public final boolean isWrapText()
public final ObjectProperty<Font> fontProperty()
public final void setFont(Font value)
public final Font getFont()
public final ObjectProperty<Node> graphicProperty()
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.public final void setGraphic(Node value)
public final Node getGraphic()
private StyleableStringProperty imageUrlProperty()
public final ObjectProperty<ContentDisplay> contentDisplayProperty()
public final void setContentDisplay(ContentDisplay value)
public final ContentDisplay getContentDisplay()
public final DoubleProperty graphicTextGapProperty()
public final void setGraphicTextGap(double value)
public final double getGraphicTextGap()
final void setActivated(boolean value)
public final boolean isActivated()
public final ReadOnlyBooleanProperty activatedProperty()
protected Skin<?> createDefaultSkin()
-fx-skin
or set explicitly in a sub-class with setSkin(...)
.createDefaultSkin
in class PopupControl
public static java.util.List<CssMetaData<? extends Styleable,?>> getClassCssMetaData()
public java.util.List<CssMetaData<? extends Styleable,?>> getCssMetaData()
getCssMetaData
in interface Styleable
getCssMetaData
in class PopupControl
public Styleable getStyleableParent()
PopupControl
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.getStyleableParent
in interface Styleable
getStyleableParent
in class PopupControl
PopupWindow.getOwnerNode()
, PopupWindow.getOwnerWindow()
,
or null.