Example usage for java.awt Color decode

List of usage examples for java.awt Color decode

Introduction

In this page you can find the example usage for java.awt Color decode.

Prototype

public static Color decode(String nm) throws NumberFormatException 

Source Link

Document

Converts a String to an integer and returns the specified opaque Color .

Usage

From source file:Main.java

public static void main(String[] args) {
    Color myColor = Color.decode("0XFFFFFF");

    JLabel label = new JLabel("First Name");
    label.setForeground(myColor);//from   ww  w  .  j av a2s  .  c o  m

    JFrame frame = new JFrame();
    frame.add(label);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setBounds(20, 20, 500, 500);
    frame.setVisible(true);

}

From source file:Main.java

public static void lookNimbus(Component comp) {
    UIManager.LookAndFeelInfo[] looks = UIManager.getInstalledLookAndFeels();
    for (UIManager.LookAndFeelInfo look : looks) {
        if (look.getClassName().matches("(?i).*nimbus.*")) {
            try {
                UIManager.setLookAndFeel(look.getClassName());

                //                UIManager.put("control", Color.decode("#cccccc"));
                UIManager.put("info", Color.decode("#ff9900"));
                //                UIManager.put("nimbusAlertYellow", Color.decode("#ff0000"));
                //                UIManager.put("nimbusBase", Color.decode("#4e5a66"));
                //                UIManager.put("nimbusDisabledText", Color.decode("#9900ff"));
                UIManager.put("nimbusFocus", Color.decode("#ff9933"));
                //                UIManager.put("nimbusGreen", new Color(130, 133, 37));
                //                UIManager.put("nimbusInfoBlue", Color.decode("#9900ff"));
                //                UIManager.put("nimbusLightBackground", Color.decode("#9900ff"));
                //                UIManager.put("nimbusOrange", new Color(191, 98, 4));
                //                UIManager.put("nimbusRed", new Color(169, 46, 34));
                //                UIManager.put("nimbusSelectedText", Color.decode("#ff00ff"));
                UIManager.put("nimbusSelectionBackground", Color.decode("#465059"));
                //                UIManager.put("text", new Color(0, 0, 0));

                UIManager.put("nimbusSelection", Color.decode("#465059"));
                //                UIManager.put("Menu.background", Color.decode("#0066ff"));
                //                UIManager.put("Menu[Enabled+Selected].backgroundPainter", Color.BLUE);

                SwingUtilities.updateComponentTreeUI(comp);
                return;
            } catch (Exception e) {
                e.printStackTrace();// www .java2 s . c  o m
            }
        }
    }
}

From source file:Main.java

/**
 * return a color value from a string specification.
 *//*from  w w w  .  ja  v  a2 s .  c o m*/
public static Color colorValue(String colorName) {
    if (colorName == null) {
        return null;
    }

    colorName = colorName.trim().toLowerCase();

    Color color = colorMap.get(colorName);

    if (color == null && colorName.startsWith("rgb")) {
        color = rgbStringToColor(colorName);
    }
    if (color == null) {
        color = Color.decode(colorName);
    }

    return color;
}

From source file:Main.java

/**
 * Hex to color.//  w  w w .j  av  a2 s  .c  o  m
 *
 * @param colorHex
 *            the color hex
 * @return the color
 */
public static Color hexToColor(String colorHex) {
    final String replace = colorHex.replace("#", "0x");
    // System.out.println(replace);
    return Color.decode(replace);
}

From source file:Main.java

public static Color getColorProperty(Map p, Object key, Color defaultValue) {
    Object value = p.get(key);//from w  ww.j a va 2  s .  co m

    if (value instanceof Color)
        return (Color) value;
    else if (value instanceof String) {
        try {
            return Color.decode((String) value);
        } catch (NumberFormatException e) {
        }
    }
    return defaultValue;
}

From source file:com.uttesh.pdfngreport.util.chart.ChartStyle.java

/**
 * this method will set the style theme for pie chart.
 *
 * @see org.jfree.chart.StandardChartTheme
 * @param chart/*from   ww  w.  j  a  v  a 2  s .  c o  m*/
 */
public static void theme(JFreeChart chart) {
    String fontName = "Lucida Sans";

    StandardChartTheme theme = (StandardChartTheme) org.jfree.chart.StandardChartTheme.createJFreeTheme();

    theme.setTitlePaint(Color.decode("#4572a7"));
    theme.setExtraLargeFont(new Font(fontName, Font.PLAIN, 16)); //title
    theme.setLargeFont(new Font(fontName, Font.BOLD, 15)); //axis-title
    theme.setRegularFont(new Font(fontName, Font.PLAIN, 11));
    theme.setRangeGridlinePaint(Color.decode("#C0C0C0"));
    theme.setPlotBackgroundPaint(Color.white);
    theme.setChartBackgroundPaint(Color.white);
    theme.setGridBandPaint(Color.red);
    theme.setAxisOffset(new RectangleInsets(0, 0, 0, 0));
    theme.setBarPainter(new StandardBarPainter());
    theme.setAxisLabelPaint(Color.decode("#666666"));
    theme.apply(chart);
    chart.setTextAntiAlias(true);
    chart.setAntiAlias(true);
}

From source file:se.trixon.almond.GraphicsHelper.java

public static Color colorAndMask(Color color, int mask) {
    int baseColor = GraphicsHelper.colorToHexInt(color);
    Integer activeColorValue = baseColor & mask;

    Color maskedColor = Color.decode("#" + Integer.toHexString(activeColorValue.intValue()));

    return maskedColor;
}

From source file:SystemAnomalies.bouncedLogInRate.java

public bouncedLogInRate() {
    setSize(700, 700);
    setLocation(0, 0);
    setBackground(Color.decode("#084061"));
    setLayout(null);

    add(getChartPanel());

}

From source file:no.java.swing.resource.ColorResourceConverter.java

@Override
public Color convert(String value) {
    if (value.startsWith("#") || StringUtils.isNumeric(value)) {
        try {/*from w w w .jav a  2  s  .  c  o m*/
            return Color.decode(value);
        } catch (NumberFormatException e) {
            throw new ResourceConversionException(e);
        }
    } else if (value.contains(",")) {
        String[] split = value.split(",");
        if (split.length != 3) {
            throw new ResourceConversionException("Cannot convert from a None RGB color, value was " + value);
        }
        try {
            return new Color(NumberUtils.toInt(split[0], -1), NumberUtils.toInt(split[1], -1),
                    NumberUtils.toInt(split[2], -1));
        } catch (IllegalArgumentException e) {
            throw new ResourceConversionException(e);
        }
    }
    throw new ResourceConversionException("Unrecognized Color format " + value);
}

From source file:Main.java

/**
 * Converts a given string into a color.
 * /*from w w  w .  j a va2s.  co  m*/
 * @param value
 *          the string, either a name or a hex-string.
 * @return the color.
 */
public static Color stringToColor(final String value) {
    if (value == null) {
        return Color.black;
    }
    try {
        // get color by hex or octal value
        return Color.decode(value);
    } catch (NumberFormatException nfe) {
        // if we can't decode lets try to get it by name
        try {
            // try to get a color by name using reflection
            final Field f = Color.class.getField(value);

            return (Color) f.get(null);
        } catch (Exception ce) {
            // if we can't get any color return black
            return Color.black;
        }
    }
}