JavaFX Tutorial - JavaFX Tooltip

The tooltip appears when that control is hovered over by the mouse cursor.

The tooltip is used to display additional information about the UI control.

We can install the tooltip by calling the setTooltip method.

The tooltip has two different states: activated and showing. There is some delay between activated and shown states.

Creating a Tooltip

The following code installs a tooltip to a password field. It calls the default constructor of Tooltip class.

PasswordField pf = new PasswordField();
Tooltip tooltip = new Tooltip();

Each UI control from javafx.scene.control package has the setTooltip method.

We can also create a Tooltip object by passing in a text caption with a Tooltip constructor.

Tooltip class extends the Labeled class can have a text caption as well as graphical icon.

The following code installs an icon to the tooltip.

Image image = new Image(getClass().getResourceAsStream("warn.png"));
tooltip.setGraphic(new ImageView(image));