Here you can find the source of stringToColor(String color)
public static Color stringToColor(String color)
//package com.java2s; /**/*from w w w . jav a2s.co m*/ * Copyright 2012 Universitat Pompeu Fabra. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * */ import java.awt.*; public class Main { public static Color stringToColor(String color) { if (color == null) { return null; } int r = 0, g = 0, b = 0; try { String tmpcolor = color.trim(); tmpcolor = tmpcolor.substring(1, tmpcolor.length() - 1); String rgb[] = tmpcolor.split(","); r = Integer.valueOf(rgb[0]).intValue(); g = Integer.valueOf(rgb[1]).intValue(); b = Integer.valueOf(rgb[2]).intValue(); return new Color(r, g, b); } catch (Exception e) { throw new UnsupportedOperationException( "The color '" + color + "' is malformed. Syntax: [r,g,b] Example: \"[128,12,34]\"", e); } } }