Java Swing UIManager getHyperlinkForeground()

Here you can find the source of getHyperlinkForeground()

Description

Returns the color to use for hyperlink-style components.

License

BSD License

Return

The color to use for hyperlinks.

Declaration

public static final Color getHyperlinkForeground() 

Method Source Code

//package com.java2s;
/*//from ww  w  . j  a va  2s.  c o  m
 * 08/06/2004
 *
 * RSyntaxUtilities.java - Utility methods used by RSyntaxTextArea and its
 * views.
 * 
 * This library is distributed under a modified BSD license.  See the included
 * RSyntaxTextArea.License.txt file for details.
 */

import java.awt.Color;

import javax.swing.*;

public class Main {
    /**
     * Used for the color of hyperlinks when a LookAndFeel uses light text
     * against a dark background.
     */
    private static final Color LIGHT_HYPERLINK_FG = new Color(0xd8ffff);

    /**
     * Returns the color to use for hyperlink-style components.  This method
     * will return <code>Color.blue</code> unless it appears that the current
     * LookAndFeel uses light text on a dark background, in which case a
     * brighter alternative is returned.
     *
     * @return The color to use for hyperlinks.
     * @see #isLightForeground(Color)
     */
    public static final Color getHyperlinkForeground() {

        // This property is defined by all standard LaFs, even Nimbus (!),
        // but you never know what crazy LaFs there are...
        Color fg = UIManager.getColor("Label.foreground");
        if (fg == null) {
            fg = new JLabel().getForeground();
        }

        return isLightForeground(fg) ? LIGHT_HYPERLINK_FG : Color.blue;

    }

    /**
     * Returns whether the specified color is "light" to use as a foreground.
     * Colors that return <code>true</code> indicate that the current Look and
     * Feel probably uses light text colors on a dark background.
     *
     * @param fg The foreground color.
     * @return Whether it is a "light" foreground color.
     * @see #getHyperlinkForeground()
     */
    public static final boolean isLightForeground(Color fg) {
        return fg.getRed() > 0xa0 && fg.getGreen() > 0xa0
                && fg.getBlue() > 0xa0;
    }
}

Related

  1. getDefaultForeground()
  2. getDefaultInactiveBackgroundColour()
  3. getErrorIcon()
  4. getGrayFilter()
  5. getGtkThemeName()
  6. getIcon(String iconResource)
  7. getIconForeground()
  8. getListBackground(final boolean selected)
  9. getListForeground()