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?
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".
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.
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.
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.
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.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With