public static Color nameToColor ( String strColor ) { final Object [ ] [ ] obj = { { "black" , Color . black } , { "blue" , Color . blue } , { "cyan" , Color . cyan } , { "darkGray" , Color . darkGray } , { "gray" , Color . gray } , { "green" , Color . green } , { "lightGray" , Color . lightGray } , { "magenta" , Color . magenta } , { "orange" , Color . orange } , { "pink" , Color . pink } , { "red" , Color . red } , { "white" , Color . white } , { "yellow" , Color . yellow } } ; // Not static, because this method is usually not called. for ( int i = 0 ; i < obj . length ; i ++ ) { if ( strColor . equalsIgnoreCase ( ( String ) obj [ i ] [ 0 ] ) ) return ( Color ) obj [ i ] [ 1 ] ; } try { return Color . decode ( strColor ) ; } catch ( NumberFormatException ex ) { } return null ; }
Convert this color string to the Color object .