Create Colored ToolTip Example in Java

Description

The following code shows how to create Colored ToolTip Example.

Example


//from  w  w  w . j  a v  a 2 s  . c  o  m
import java.awt.Color;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.plaf.ColorUIResource;

public class Main extends JFrame {
  public Main() {
    super("Colored ToolTip Example");

    UIManager.put("ToolTip.foreground", new ColorUIResource(Color.red));
    UIManager.put("ToolTip.background", new ColorUIResource(Color.yellow));

    JButton button = new JButton("Hello, world");
    button.setToolTipText("Red / Yellow");
    getContentPane().add(button);
  }

  public static void main(String args[]) {
    Main f = new Main();
    f.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
      }
    });
    f.setSize(300, 100);
    f.show();
  }
}

The code above generates the following result.

Create Colored ToolTip Example in Java




















Home »
  Java Tutorial »
    Swing »




Action
Border
Color Chooser
Drag and Drop
Event
Font Chooser
JButton
JCheckBox
JComboBox
JDialog
JEditorPane
JFileChooser
JFormattedText
JFrame
JLabel
JList
JOptionPane
JPasswordField
JProgressBar
JRadioButton
JScrollBar
JScrollPane
JSeparator
JSlider
JSpinner
JSplitPane
JTabbedPane
JTable
JTextArea
JTextField
JTextPane
JToggleButton
JToolTip
JTree
Layout
Menu
Timer