import java.awt.BorderLayout;
import java.awt.Container;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JToolTip;
import java.awt.Color;

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);
    }
}