Returns a color to use for "error" text in a text field. - Java Swing

Java examples for Swing:JTextField

Description

Returns a color to use for "error" text in a text field.

Demo Code

/*//from  w w w.  j av  a 2 s .c  om
 * 09/08/2005
 *
 * UIUtil.java - Utility methods for org.fife.rsta.ui classes.
 * This library is distributed under a modified BSD license.  See the included
 * RSTAUI.License.txt file for details.
 */
//package com.java2s;
import java.awt.Color;

import javax.swing.UIManager;

public class Main {
    /**
     * Returns a color to use for "error" text in a text field.  This will
     * pick red for dark-text-on-light-background LookAndFeels, and a
     * brighter color for light-text-on-dark-background LookAndFeels.
     *
     * @return The color to use.
     */
    public static final Color getErrorTextForeground() {
        Color defaultFG = UIManager.getColor("TextField.foreground");
        if (defaultFG.getRed() >= 160 && defaultFG.getGreen() >= 160
                && defaultFG.getBlue() >= 160) {
            return new Color(255, 160, 160);
        }
        return Color.red;
    }
}

Related Tutorials