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