Dynamic Tooltip in Java
Tuesday, 1 April 2014Tooltip is helpful for every software users it displays the use of that feature of a software and also it make it easy for the user to work with that software.
In this project we will develop a project with Tooltip Functionality,It is developed with the help of Netbeans Ide It is a Graphical User Interface application.
Now,Open up Netbeans Ide
Go to ,
- File--->New Project
- Categories—>java
- Project—>Java Desktop Application
Click Next and then Finish
Now switch to design view add a jbutton from palatte
Now swtch to source view
Import the following package.
import com.sun.media.ui.ToolTip;
Declare ToolTip as class level variable like that
ToolTip tip=new ToolTip("set your text here");
find this function and write this code below it initComponents();
tip.setLocationRelativeTo(jButton1); //displays tooltip below jbutton
tip.setSize(200,50);
That’s it.
Now right click jbutton in design view and got to
Events—>Mouse—>MouseEntered
You will see the code like this
private void jButton1MouseEntered(java.awt.event.MouseEvent evt) {
tip.setVisible(true); //setting visible tooltip
}Now again go to design view and right click jbutton
Events—>Mouse—>MouseExited
You will see the code like this
private void jButton1MouseExited(java.awt.event.MouseEvent evt) {
tip.setVisible(false); //setting invisible tooltip
}All done compile and run move cursor to jbutton and see the tooltip.