JButton tooltip code examaple
Its easy to use JButton tooltip Method.All you need to do is add JButton, to a JFrame add JButton actionListener and lastly call tooltip method.
Adding JButton Tooltip Example
[
import javax.swing.JFrame; import javax.swing.JButton; import javax.swing.UIManager; public class JButtonTooltipExample { public static void main(String args[]) { try { UIManager.setLookAndFeel ("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel"); } catch(Exception e) { e.printStackTrace(); } JFrame f=new JFrame("JButton Tooltip Example"); JButton button=new JButton("Save"); button.setToolTipText("Click here to save data to the database"); f.add(button); f.setSize(300, 300); f.setLocationRelativeTo(null); f.setVisible(true); } }
]
JButton tooltip Example Code Analysis
At the top of this program is import section.I have imported JFrame, user onJButton and UIManager swing components.
I normally like setting my programs to WindowsClassicLookAndFeel.
button.setToolTipText("Click here to save data to the database")-sets the tooltip text.When the mouse cursor hovers on top of the JButton, Normally the text is diGenerally tooltip text guides the user on what to do.