java.awt.Color should get a toHexString()-method

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Unresolved
    • Priority: P5
    • None
    • Affects Version/s: 7
    • Component/s: client-libs
    • x86
    • windows_xp

      A DESCRIPTION OF THE REQUEST :
      The Color-class already has a method, which converts a string of the type #RRGGBB into a RGB-Color-Value and creates a new java.awt.Color instanse from them.

      I think it would be usefull to many developers to have a method doing the opposite thing. It could be called for examplte 'toHexString()' or 'encode()' (as a counterpart to the existing 'decode()'-method, that i mentioned above).

      JUSTIFICATION :
      It think such method would be used very often and therefore should be a part of the class


      ---------- BEGIN SOURCE ----------
      Just a possible implementation, which i am currently using:

        public String toHexString() {
          StringBuilder sb = new StringBuilder(7);
          String r = Integer.toHexString(getRed());
          String g = Integer.toHexString(getGreen());
          String b = Integer.toHexString(getBlue());
          sb.append("#");
          if (r.length() == 1)
            sb.append('0');
          sb.append(r);
          if (g.length() == 1)
            sb.append('0');
          sb.append(g);
          if (b.length() == 1)
            sb.append('0');
          sb.append(b);
          return sb.toString();
        }

      ---------- END SOURCE ----------

            Assignee:
            Unassigned
            Reporter:
            Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: