We can add tooltip text to almost all the components of Java Swing by using the following method setToolTipText(String s). This method sets the tooltip of the component to the specified string s . When the cursor enters the boundary of that component a popup appears and text is displayed .
- getToolTipText() : returns the tooltip text for that component .
- setToolTipText(String s) : sets the tooltip text for the component .
- getToolTipText(MouseEvent e): returns the same value returned by getToolTipText(). Multi-part components such as JTabbedPane, JTable, and JTree override this method to return a string associated with the mouse event location.
- getToolTipLocation(MouseEvent e) : Returns the location (in the receiving component’s coordinate system) where the upper left corner of the component’s tool tip appears.
The following programs will illustrate the use of tooltiptext
1. Program to create a textarea and single line tool tip text to it
2. Program to create a text area and add multiple line tooltip text to it.
3. program to submit name using JTextField and the tooltip text shows the previous entries.(using getToolTipText function)
Note : the following programs might not run in an online compiler please use an online IDE.
- Java Swing | Translucent and shaped Window in Java
- Java Swing | JTextArea
- Java Swing | JTextField
- Java Swing | JProgressBar
- Java Swing | JPasswordField
- Java Swing | JSpinner
- Java Swing | JTable
- Java Swing | JToolBar
- JRadioButton | Java Swing
- Java Swing | MatteBorder
- Java Swing | JPopupMenu
- Java Swing | JSlider
- JLabel | Java Swing
- Java Swing | JMenuBar
- Java Swing | JFileChooser
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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