Saturday, 28 March 2015

How To Add Tool Tip Text On JButton

This tutorial shows how to use tooltip.Tooltip can be used to give detail about component when user move the mouse over the button it appears this example shows better implementation of it.


METHODS OF TOOL TIP TEXT:

setToolTipText(String)
String getToolTipText()
String getToolTipText(MouseEvent)
Point getToolTipLocation(MouseEvent)

As you can see we have used first constructor to set tooltip text.Second constructor is used get tool tip text of a component the use of second constructor is also same but it's used when there are multi part component such as jtable then it will only return that text that is associated with mouse event.


CODING:

import javax.swing.*;
import java.awt.*;

class tab extends JFrame

{
JButton jb;
tab()
{
super();
setTitle("Tool Tip Text");
setSize(250, 300);
setVisible(true);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);      
jb =new JButton("BUTTON");
FlowLayout f=new FlowLayout();
setLayout(f);
add(jb);
jb.setToolTipText("This is ToolTip Text.");
}


}
class nbutt
{
public static void main(String args[])
{
tab x= new tab();
}

}

OUTPUT:




No comments:

Post a Comment