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"));
extends