Java Color Create toColor(String background)

Here you can find the source of toColor(String background)

Description

Get the Color object matching with the given string.

License

Open Source License

Parameter

Parameter Description
background A string representing the color. It will be given to Color#decode(String) .

Exception

Parameter Description
NumberFormatException if the specified string cannot be interpretedas a decimal, octal, or hexidecimal integer.

Return

The color object, or null if the given string is null .

Declaration

public static Color toColor(String background) throws NumberFormatException 

Method Source Code


//package com.java2s;
/*//from   w w w.  ja va2 s .com
 *    Geotoolkit - An Open Source Java GIS Toolkit
 *    http://www.geotoolkit.org
 *
 *    (C) 2008 - 2010, Geomatys
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation; either
 *    version 2.1 of the License, or (at your option) any later version.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 */

import java.awt.Color;

public class Main {
    /**
     * Get the {@link Color} object matching with the given string.
     *
     * @param background A string representing the color. It will be given to
     *                   {@link Color#decode(String)}.
     * @return The color object, or {@code null} if the given string is {@code null}.
     * @throws NumberFormatException if the specified string cannot be interpreted
     *                               as a decimal, octal, or hexidecimal integer.
     */
    public static Color toColor(String background) throws NumberFormatException {
        Color color = null;
        if (background != null) {
            background = background.trim();
            color = Color.decode(background);
        }
        return color;
    }
}

Related

  1. toColor(float[] color)
  2. toColor(int rgba)
  3. toColor(int x)
  4. toColor(Node n)
  5. toColor(short rgb565)
  6. toColor(String hexString)
  7. toColor(String pString)
  8. toColor(String str)
  9. toColors(boolean hasAlpha, int... colors)