JavaFX Tooltip Example

In this tutorial, we will learn how to use tooltip in the JavaFX application.

Any node can show a tooltip. Tooltip is a common UI element that is typically used for showing additional information about a node in the scene graph. It is shown when we hover a mouse pointer over a node.

JavaFX Tooltip Example

In the example, we set a tooltip to a button control:

package com.javaguides.javafx;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

public class TooltipExample extends Application {

    public void start(Stage stage) {
        HBox root = new HBox();
        root.setPadding(new Insets(20));

        Button btn = new Button("Button");
        btn.setMaxSize(100, 25);
        Tooltip tooltip = new Tooltip("Showing Tooltip");
        Tooltip.install(btn, tooltip);


        Scene scene = new Scene(root, 500, 350);


    public static void main(String[] args) {

Let's understand the above JavaFX program.

A Button control is instantiated:

Button btn = new Button("Button");

A Tooltip is created and set to the button with the Tooltip's install() method:

Tooltiptooltip = new Tooltip("Button control");
Tooltip.install(btn, tooltip);


Related JavaFX Examples

Free Spring Boot Tutorial | Full In-depth Course | Learn Spring Boot in 10 Hours

Watch this course on YouTube at Spring Boot Tutorial | Fee 10 Hours Full Course