Tooltip is a part of JavaFx package. Tooltip is used to show additional information to the user when the mouse is hovered over the component. All the components can be associated with a tooltip and it can be also associated with a part of screen.
Constructors of the Tooltip class:
- Tooltip(): Creates a tooltip with an empty string for its text.
- Tooltip(String t): Creates a tooltip with the specified text.
Commonly used methods:
|getFont()||Gets the value of the property font.|
|getText()||Gets the value of the property text.|
|getTextAlignment()||Gets the value of the property textAlignment.|
|install(Node n, Tooltip t)||Associates the given Tooltip with the given Node.|
|isActivated()||Gets the value of the property activated.|
|setFont(Font v)||Sets the value of the property font.|
|setText(String v)||Sets the value of the property text.|
|setTextAlignment(TextAlignment v)||Sets the value of the property textAlignment.|
Below program illustrate the use of Tooltip in Java:
Program to create a label and add Tooltip text to the labels: We will create 3 tooltip objects t, t1, t2 for labels l, l1 l2. Then we will set the font for two labels t1 and t2. For t we will set Arial font and for t1 Tooltip we will set Verdana font. We will set the textAlignment for text of t1 and t2 to Left and Right respectively and we can set the tooltip to a label using two ways: The first is by using setTooltip() function and other using install() function. After that a Tile-pane is created, on which addChildren() method is called to attach the labels inside the scene, along with the resolution specified by (200, 200) in the code. Finally the show() method is called to display the final results.
Note: The above programs might not run in an online IDE please use an offline compiler.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Java Swing | ToolTip
- JavaFX | Pos Class
- JavaFX | Box with examples
- JavaFX | Arc with examples
- JavaFX | ChoiceDialog
- JavaFX | MenuButton
- JavaFX | ChoiceBox
- JavaFX | Checkbox
- JavaFX | CustomMenuItem
- JavaFX | TextInputDialog
- JavaFX | ProgressBar
- JavaFx | PasswordField
- JavaFX | Tab Class
- JavaFX | Label
- JavaFX | TextField
- JavaFX | ProgressIndicator
- JavaFX | Stop Class
- JavaFX | LineTo class
- JavaFX | ClosePath class
- JavaFX | SplitPane Class
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : ManasChhabra2