Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4017234

need a method which returns a Color when passed a String color name

XMLWordPrintable

    • generic
    • solaris_10

      From ###@###.### Tue Nov 26 17:06:11 1996
      MIME-Version: 1.0
      To: java-awt@java
      Subject: 1.1 changes to java.awt.Colors
      Content-Transfer-Encoding: 7bit

      Hi, I was a bit disappointed that there was no color lookup
      by name in 1.1. it would be helpful if individual applications
      did not have to decide how to name various RGB triplets.

      I don't know what to suggest for the list of color names, although
      Motif's rgb.txt is one choice. I would prefer that. Another
      choice might be the limited set of colors directly supported
      by Netscape because they have the best representation on a large
      set of platforms, e.g.,

        http://www.electriciti.com/~rschmitt/toolbox/nspalette/index.html

      As far as I know, these colors have no official name.

      The unhappy alternative is that everyone codes their own hokey
      lookups like this, just so they can offer -fg and -bg switches
      to their users.

      class ColorFromName
      {
      public static Color getColor(String name_)
        {
          if ( name_ == null || name_.trim().length() == 0 )
            return null ;
          if ( name_.equals("white")) return new Color(255, 255, 255);
          if ( name_.equals("lightGray")) return new Color(192, 192, 192);
          if ( name_.equals("gray")) return new Color(128, 128, 128);
          if ( name_.equals("darkGray")) return new Color( 64, 64, 64);
          if ( name_.equals("black")) return new Color( 0, 0, 0);
          if ( name_.equals("red")) return new Color(255, 0, 0);
          if ( name_.equals("pink")) return new Color(255, 175, 175);
          if ( name_.equals("orange")) return new Color(255, 200, 0);
          if ( name_.equals("yellow")) return new Color(255, 255, 0);
          if ( name_.equals("green")) return new Color( 0, 255, 0);
          if ( name_.equals("magenta")) return new Color(255, 0, 255);
          if ( name_.equals("cyan")) return new Color( 0, 255, 255);
          if ( name_.equals("blue")) return new Color( 0, 0, 255);
          return null ;
        }
      }

      Thsnks for your consideration.

      t

            rraysunw Richard Ray (Inactive)
            amfowler Anne Fowler (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: