Is there a simple way to display hint texts in JavaFX?

MKaama picture MKaama · Aug 16, 2014 · Viewed 17.7k times · Source

In the Borland VCL library, almost all controls had a hint property. During runtime, when you position mouse over the respective control, a small box with the hint text pops up and disappears again when you move the mouse, like the help messages in Windows Explorer and other programs, when mouse cursor is being held over a button.

Is there a similar concept in JavaFX (actually, I am using ScalaFX)?

Of course, I can create a new stage without decorations, add some mouse listeners etc., but is it not already available somewhere?

Answer

jewelsea picture jewelsea · Aug 16, 2014

You can use a Tooltip control.

Usage Sample

If you want the tooltip on a Control, for example a button, set the tooltip:

button.setTooltip(
    new Tooltip("Button of doom")
);

Otherwise, for other node types like shapes, install the tooltip:

Circle circle = new Circle(15, 15, 42);
Tooltip.install(
    circle,
    new Tooltip("Circle of light")
);

Tutorial

Oracle have a tutorial dedicated just to Tooltips.

tooltip image

As you can see above, you can set a "graphic" on a tooltip, which can be an image (or any other node), it's pretty flexible.

Tooltip Styling

Other Options

If Tooltip isn't what you are looking for, there are other ways to show popups: