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.)

Main.java:

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();
      tooltip.setBackground(Color.red);
      tooltip.setForeground(Color.yellow);
 
      JLabel label = new JLabel("How was I?") {
         public JToolTip createToolTip() {
            return tooltip;
         }
      };
 
      label.setToolTipText("too commercial");
    
      getContentPane().add(label);
 
      addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
            System.exit(0);
         }
      });
 
      setSize(400, 300);
   }
 
   public static void main(String[] args) {
      Main main = new Main();
      main.setVisible(true);
   }
}