Home | | Web Programming | Adding Tooltips - JavaFX

Chapter: Java The Complete Reference : Introducing GUI Programming with JavaFX : Exploring JavaFX Controls

Adding Tooltips - JavaFX

One very popular element in the modern GUI is the tooltip. A tooltip is a short message that is displayed when the mouse hovers over a control.

Adding Tooltips

 

One very popular element in the modern GUI is the tooltip. A tooltip is a short message that is displayed when the mouse hovers over a control. In JavaFX, a tooltip can be easily added to any control. Frankly, because of the benefits that tooltips offer and the ease by which they can be incorporated into your GUI, there is virtually no reason not to use them where appropriate.

 

To add a tooltip, you call the setTooltip( ) method defined by Control. (Control is a base class for all controls.) The setTooltip( ) method is shown here:

 

final void setTooltip(Tooltip tip)

 

In this case, tip is an instance of Tooltip, which specifies the tooltip. Once a tooltip has been set, it is automatically displayed when the mouse hovers over the control. No other action is required on your part.

The Tooltip class encapsulates a tooltip. This is the constructor that we will use: Tooltip(String str)

Here, str specifies the message that will be displayed by the tooltip.

 

To see tooltips in action, try adding the following statements to the CheckboxDemo program shown earlier.

 

cbWeb.setTooltip(new Tooltip("Deploy to Web")); cbDesktop.setTooltip(new Tooltip("Deploy to Desktop")); cbMobile.setTooltip(new Tooltip("Deploy to Mobile"));

 

After these additions, the tooltips will be displayed for each check box.

 

Disabling a Control

 

Before leaving the subject of controls, it is useful to describe one more feature. Any node in the scene graph, including a control, can be disabled under program control. To disable a control, use setDisable( ), defined by Node. It is shown here:

 

final void setDisable(boolean disable)

 

If disable is true, the control is disabled; otherwise, it is enabled. Thus, using setDisable( ), you can disable a control and then enable it later.

 

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
Java The Complete Reference : Introducing GUI Programming with JavaFX : Exploring JavaFX Controls : Adding Tooltips - JavaFX |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2024 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.