Search code examples
javaswingtooltip

How do I change the color of the tooltip for only one component?


How do I change the color of the tooltip for only one component?

I know you can do the following for changing tooltip colors:

UIManager.put("ToolTip.background", new ColorUIResource(255, 247, 200)); 

But this changes the tooltip background for all component, not just one.

Any easy solutions?


Solution

  • You need to provide a custom JTooltip for the component.

    Take a look at JComponent#createToolTip

    From the Java Docs

    Returns the instance of JToolTip that should be used to display the tooltip. Components typically would not override this method, but it can be used to cause different tooltips to be displayed differently.