Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 489
MKaama Avatar asked Aug 16 '14 09:08

MKaama


People also ask

How do I set the prompt text in JavaFX?

In JavaFX, we can set add prompt text to a text field using the setPromptText() function. This is shown in the code below. Inside of this setPromptText() function, we pass a parameter to the prompt text that we want to display. In this example, we pass in, "Enter your name".

What is prompt text in JavaFX?

The TextField class in JavaFX is used to create a control that allows the user to enter in a single line of text. It supports having prompt text (i.e., text that informs the user what the TextField is meant to be used for). Note: If you need a multi-line text input control then have a look at the TextArea class.

What is tooltip in JavaFX?

Tooltips are common UI elements which are typically used for showing additional information about a Node in the scenegraph when the Node is hovered over by the mouse. Any Node can show a tooltip. In most cases a Tooltip is created and its text property is modified to show plain text to the user.

How do you create an input textbox in JavaFX?

To create a text field, you need to instantiate the TextField class, to the constructor of this class you can also pass a string value which will be the initial text of the text field.


1 Answers

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

  • Tooltip background (with JavaFX CSS)

Other Options

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

  • JavaFX 2 custom popup pane
like image 163
jewelsea Avatar answered Oct 07 '22 02:10

jewelsea