JavaFX Tutorial - Java Tooltip.textProperty()








Syntax

Tooltip.textProperty() has the following syntax.

public final StringProperty textProperty()

Example

In the following code shows how to use Tooltip.textProperty() method.

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Tooltip;
import javafx.stage.Stage;
//from  www  .ja v a  2 s . com

public class Main extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage stage) {
        Scene scene = new Scene(new Group());
        stage.setWidth(300);
        stage.setHeight(150);

        Button button = new Button("Hover Over Me");
        Tooltip toolTip = new Tooltip("Tooltip for Button");
        toolTip.setWrapText(true);
        System.out.println(toolTip.textProperty());
        
        button.setTooltip(toolTip); 
        ((Group) scene.getRoot()).getChildren().add(button);

        stage.setScene(scene);
        stage.show();
    }
}