Change the color of a JToolTip

To change the color of a tooltip, create a JToolTip instance and use the methods setForeground and setBackground to change its appearance. Then override the method createToolTip on the component where this tooltip applies to and return your own JToolTip instance.

(btw. to change the colors of all your tooltips, use the class UIManager and change the keys ToolTip.background and ToolTip.foreground.)

import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.awt.*;
public class Main extends JFrame {
   public Main() {
      super("JToolTip Delay Demonstration");
      getContentPane().setLayout(new FlowLayout()); 
      final JToolTip tooltip = new JToolTip();
      JLabel label = new JLabel("How was I?") {
         public JToolTip createToolTip() {
            return tooltip;
      label.setToolTipText("too commercial");
      addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
      setSize(400, 300);
   public static void main(String[] args) {
      Main main = new Main();