Thursday, March 19, 2009

Setting ToolTip and Icon

Adding Icons and ToolTips

Tooltips are shot information messages which are displayed when your mouse pointer rests at some components.That is if suppose your mose pointer is at a button whose tooltiop is set as "click here" the if your pointer comes over button the a small message will appear saying "click here".

For setting ToolTip we can use setToolTipText() method of JComponent class.

ToolTip Example:-

// tooltip.java

import javax.swing.*;
public class tooltip
{
public static void main(String a[])
{
JFrame frm=new JFrame("ToolTip Demo");
JPanel panel=new JPanel();
JLabel labeltool=new JLabel("ToolTio DemoPlace mouse over it");
labeltool.setToolTipText("This is ToolTip");
panel.add(labeltool);
frm.getContentPane().add(panel);
frm.setVisible(true);
frm.pack();
}
}

SettingIcon Example:-

// settingicon.java

import java.awt.*;
import javax.swing.*;
public class settingicon
{
public static void main(String a[])
{
JFrame frm=new JFrame("Setting Icon Demo");
JPanel panel=new JPanel();
JLabel label=new JLabel(new ImageIcon("BAK.png"));
panel.add(label);
frm.getContentPane().add(panel);
frm.setVisible(true);
frm.pack();
}
}

0 comments:

About This Blog

This Blog is all about Java and programming.This blog is written by Vaibhav Pandey(Read More about him) .He is a Computer Science Graduate .You can contact the author at javatute@gmail.com for any suggestion or Query.You can also contact the author for advertising on this blog.All the material presented here is the property of author and its reproduction in any form is strictly prohibited.

Disclaimer:-Download links provided here are not of author in any means.These are found over the Internet.
Page copy protected against web site content infringement by Copyscape

  © Blogger templates The Professional Template by Ourblogtemplates.com 2008

Back to TOP