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 | JPopupMenu
- Java Swing | JPasswordField
- JLabel | Java Swing
- Java Swing | JSpinner
- Java Swing | JMenuBar
- Java Swing | Look and Feel
- Java Swing | JFileChooser
- Java Swing | MatteBorder
- Java Swing | JProgressBar
- Java Swing | JTextField
- JRadioButton | Java Swing
- Java Swing | JToolBar
- Java Swing | JSlider
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