Java examples for Swing:JLabel
Returns the color to use for hyperlink-style components.
/*/*from w w w. j a v a2 s .c o m*/ * 09/08/2005 * * UIUtil.java - Utility methods for org.fife.ui classes. * Copyright (C) 2005 Robert Futrell * http://fifesoft.com/rtext * Licensed under a modified BSD license. * See the included license file for details. */ //package com.java2s; import java.awt.Color; import javax.swing.JLabel; import javax.swing.UIManager; 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. */ 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. */ public static final boolean isLightForeground(Color fg) { return fg.getRed() > 0xa0 && fg.getGreen() > 0xa0 && fg.getBlue() > 0xa0; } }