Java Swing UIManager getToolTipBackground()

Here you can find the source of getToolTipBackground()

Description

Returns the default background color to use for tool tip windows.

License

BSD License

Return

The default background color.

Declaration

public static Color getToolTipBackground() 

Method Source Code

//package com.java2s;
/*//from w ww  . jav  a2s  . co  m
 * 08/13/2009
 *
 * TipUtil.java - Utility methods for homemade tool tips.
 * 
 * This library is distributed under a modified BSD license.  See the included
 * RSyntaxTextArea.License.txt file for details.
 */

import java.awt.Color;

import java.awt.SystemColor;

import javax.swing.UIManager;

import javax.swing.plaf.ColorUIResource;

public class Main {
    /**
     * Returns the default background color to use for tool tip windows.
     *
     * @return The default background color.
     */
    public static Color getToolTipBackground() {

        Color c = UIManager.getColor("ToolTip.background");

        // Tooltip.background is wrong color on Nimbus (!)
        boolean isNimbus = isNimbusLookAndFeel();
        if (c == null || isNimbus) {
            c = UIManager.getColor("info"); // Used by Nimbus (and others)
            if (c == null || (isNimbus && isDerivedColor(c))) {
                c = SystemColor.info; // System default
            }
        }

        // Workaround for a bug (?) with Nimbus - calling JLabel.setBackground()
        // with a ColorUIResource does nothing, must be a normal Color
        if (c instanceof ColorUIResource) {
            c = new Color(c.getRGB());
        }

        return c;

    }

    /**
     * Returns whether the Nimbus Look and Feel is installed.
     *
     * @return Whether the current LAF is Nimbus.
     */
    private static final boolean isNimbusLookAndFeel() {
        return UIManager.getLookAndFeel().getName().equals("Nimbus");
    }

    /**
     * Returns whether a color is a Nimbus DerivedColor, which is troublesome
     * in that it doesn't use its RGB values (uses HSB instead?) and so
     * querying them is useless.
     *
     * @param c The color to check.
     * @return Whether it is a DerivedColor
     */
    private static final boolean isDerivedColor(Color c) {
        return c != null
                && c.getClass().getName().endsWith(".DerivedColor");
    }
}

Related

  1. getSeparator()
  2. getStringWidth(final String aString)
  3. getSystemDefaultModifier()
  4. getTitleBarIcon()
  5. getToolTipBackground()
  6. getToolTipForeground()
  7. getUIDefaultOfClass(Class clazz, String property)
  8. getUIDefaultOfClass(Class clazz, String property)
  9. getUIDefaultsOfClass(String className)