How can we change the background and foreground color of a JTooltip in Java?

A JToolTip is a subclass of JComponent class and we can create a tooltip for any java component by using setToolTipText() method, it can be used to set up a tooltip for the component. The important methods of a JToolTip class are getAccessibleContext(), getComponent(), paramString() and updateUI(). We can change both the background and foreground color of a JToolTip class by using the put() method of UIManager class and pass the arguments ToolTip.background and ToolTip.foreground.


import java.awt.*;
import javax.swing.*;
public class JTooltipColorTest extends JFrame {
   private JLabel label;
   public JTooltipColorTest() {
      setTitle("JTooltipColor Test");
      setLayout(new FlowLayout());
      label = new JLabel("Welcome to TutorialsPoint");
      label.setToolTipText("Simply Easy Learning");
      UIManager.put("ToolTip.background", Color.white); // to change background color of a JTtoolTip
      UIManager.put("ToolTip.foreground",; // to change foreground color of a JToolTip
      setSize(400, 300);
   public static void main(String[] args) {
      new JTooltipColorTest();