JavaFX Tooltip Tutorials

The JavaFX Tooltip is used to display additional information about the UI control(node) when the node is hovered over by the mouse.

The tooltip has two states: activated and showing.

Constructors :

  • Tooltip()Creates a tooltip with an empty string for its text.
  • Tooltip(String text)Creates a tooltip with the specified text.

Creating a Tooltip :

Tooltip tooltip = new Tooltip();
tooltip.setText("New Tooltip");

Set Tooltip for a node AS


Example of tool tip:

package javafxtuts;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class Javafxtuts extends Application {

  public static void main(String[] args) {

  public void start(Stage stage) {
      Label lb=new Label("");
      Tooltip tooltip = new Tooltip();
      tooltip.setText("One of the best website for JavaFX tutorials");
      VBox root =new VBox();
      root.setPadding(new Insets(20, 10, 10, 10));
        Scene scene = new Scene(root, 250, 200);

Output :

Explanation :

  • Tooltip tooltip = new Tooltip();It create a new Tooltip.
  • To set the text to the tooltip use setText() AStooltip.setText("One of the best website for JavaFX tutorials");
  • lb.setTooltip(tooltip);It set tooltip to the label lb.

Leave A Reply