JavaFX Tooltip Example

In this JavaFX example, we will show you how to use tooltip in the JavaFX application.

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

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

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