Tooltip Sample : Tooltip « Swing JFC « Java






Tooltip Sample

Tooltip Sample
   
import java.awt.BorderLayout;
import java.awt.Container;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JToolTip;

public class TooltipSample {

  public static void main(String args[]) {
    String title = "Tooltip Sample";
    JFrame frame = new JFrame(title);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Container container = frame.getContentPane();
    JPanel panel = new JPanel();
    panel.setToolTipText("<HtMl>Tooltip<br>Message");
    container.add(panel, BorderLayout.CENTER);

    JButton button = new JButton("Hello World") {
      public JToolTip createToolTip() {
        JToolTip tip = super.createToolTip();
        tip.setBackground(Color.yellow);
        tip.setForeground(Color.green);
        return tip;
      }

      public boolean contains(int x, int y) {
        if (x < 100) {
          setToolTipText("Got Green Eggs?");
        } else {
          setToolTipText("Got Ham?");
        }
        return super.contains(x, y);
      }
    };
    button.setToolTipText("Hello World");
    frame.getContentPane().add(button, BorderLayout.NORTH);

    frame.setSize(300, 150);
    frame.setVisible(true);
  }
}

           
         
    
    
  








Related examples in the same category

1.Html tooltipsHtml tooltips
2.Working with Tooltip TextWorking with Tooltip Text
3.MultiLine ToolTip ExampleMultiLine ToolTip Example
4.Colored ToolTip ExampleColored ToolTip Example
5.Disable / enable application tool tips
6.Making Tool Tips Remain Visible
7.Enabling and Disabling Tool Tips
8.Making Tool Tips Appear Immediately
9.Use the default tool tip location
10.Make a tool tips appear immediately
11.Showing an Image in a Tool Tip with HTML
12.Setting a Tool Tip
13.Setting the Location of a Tool Tip
14.By default, the lines are left justified. Center the lines.
15.Set the location of the tool tip such that its nw corner coincides with the bottom center of the button
16.Showing an Image in a ToolTip
17.Modify the behaviour of the default JToolTip
18.Italicize the second line
19.Changing ToolTip background color for Swing Applications
20.ToolTip Location ExampleToolTip Location Example
21.Set a tool tip for swing component
22.JToolTip With Icon