Home Java Example Java Swing Showing an image in Tool Tip
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Showing an image in Tool Tip

Advertisement
This section illustrates how to show an image in tool tip. One example is given below for illustration.

Showing an image in Tool Tip

     

This section illustrates how to show an image in tool tip. One example is given below for illustration.

This program shows a command button. When you move the mouse pointer around the button then a tool tip text will be seen with an image. Through the help of this example you can easily attach an image with the tool tip text.

Screen shot for the result of the given program:

Image Tooltip Text for a button

In this program, some html tags are using for showing the tool tip text with an image. These html tags are understood by using HTML class from the javax.swing.text.html.*; package of Java Swing. Here tooltiptext is the string variable which contains several text. Html tags are also included. This code uses the <img> tag of html which calls the image which has to be shown with the tool tip text.

Here is the code of the program:

import javax.swing.*;
import javax.swing.text.html.*;
import java.awt.*;
import java.awt.event.*;

public class ImageToolTip{
  public static void main(String[] args){
  JFrame frame = new JFrame("Image Tool Tip Frame");
  JComponent button = new JButton("Cut");
  String tooltiptext = "<html>" "This is the " 
 
"<img src=\"file:cut.gif\">"
 
   + " tool tip text." "</html>";
  button.setToolTipText(tooltiptext);
  JPanel panel = new JPanel();
  panel.add(button);
  frame.add(panel, BorderLayout.CENTER);
  frame.setSize(400400);
  frame.setVisible(true);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
}

Download this example.

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 14, 2007

Related Tutorials

Ask Questions?    Discuss: Showing an image in Tool Tip   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
vivek duneja
June 27, 2011
Thank you

your post proved useful to me thanks a lot
Md. Abdul Hannan
February 5, 2012
feel good

thank you for your very useful example
Ajit Babasaheb Doiphode
August 27, 2012
code for tool tip in jsp with image

send me
DMCA.com