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.
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Java Swing | Translucent and shaped Window in Java
- JavaFX | Tooltip
- Java Swing | ScrollPaneLayout Class
- Java Swing | JPanel with examples
- Java Swing | Internal Frame with examples
- Java Swing | JMenuBar
- Java Swing | JFileChooser
- Java Swing | Look and Feel
- Java Swing | JTextField
- Java Swing | JProgressBar
- Java Swing | JPasswordField
- Java Swing | JSpinner
- Java Swing | JPopupMenu
- Java Swing | JTextArea
- JLabel | Java Swing
- Java Swing | JToolBar
- JRadioButton | Java Swing
- Java Swing | JSlider
- Java Swing | JSplitPane with Examples
- Java Swing | JComboBox with examples
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