22 Tooltip

In this chapter, you learn about the tooltip, the control that can be set for any UI control to appear when that control is hovered over by the mouse cursor.

The Tooltip class represents a common UI component that is typically used to display additional information about the UI control. The tooltip can be set on any control by calling the setTooltip method.

The tooltip has two different states: activated and showing. When the tooltip is activated, the mouse moves over a control. When the tooltip is in the showing state, it actually appears. A shown tooltip is also activated. There is usually some delay between when the Tooltip becomes activated and when it is actually shown.

Each UI control from the javafx.scene.control package has the setTooltip method to add a tooltip. You can define a text caption within a Tooltip constructor or by using the setText method.

Because the Tooltip class is an extension of the Labeled class, you can add not only a text caption, but a graphical icon as well. The code fragment in Example 22-2 adds an icon to the tooltip for the password field.

Each checkbox is accompanied by a tooltip. Each tooltip displays the rate for a particular booking option. If a user selects a checkbox, the corresponding value is added to the total. If a selected checkbox is deselected, the corresponding value is deducted from the total.