an array of the colors in java.awt.color

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • praclarush
    New Member
    • Oct 2007
    • 27

    #1

    an array of the colors in java.awt.color

    Its been a while since i've writen a java program so I was wondering whats the best way to get an array of the colors in the java.awt.color class. So I can use it to populate a JList. All i'm asking for is a little help in getting started or pointed in the right direction.

    Thanks Praclarush
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    Are you talking about the constant colors included in java.awt.Color, or all possible colors?

    Comment

    • praclarush
      New Member
      • Oct 2007
      • 27

      #3
      Originally posted by Ganon11
      Are you talking about the constant colors included in java.awt.Color, or all possible colors?
      just the constant ones,

      Comment

      • Ganon11
        Recognized Expert Specialist
        • Oct 2006
        • 3651

        #4
        it looks like the best way would just be to take the time and type out each constant into your array. You can save some time by copy/pasting the "Color." portion...

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by praclarush
          just the constant ones,
          Why not simply use reflection on the Color class then? e.g.

          [code=java]
          String name= ...
          Color color= (Color)Color.cl ass.getField(na me).get();
          [/code]

          You have to wrap that code snippet in a try ... catch block for obvious reasons.

          kind regards,

          Jos

          Comment

          • BigDaddyLH
            Recognized Expert Top Contributor
            • Dec 2007
            • 1216

            #6
            Originally posted by JosAH
            Why not simply use reflection on the Color class then? e.g.

            [code=java]
            String name= ...
            Color color= (Color)Color.cl ass.getField(na me).get();
            [/code]

            You have to wrap that code snippet in a try ... catch block for obvious reasons.

            kind regards,

            Jos
            Sometimes one's behaviour is punishment enough. I hope you like Color.PINK.

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Originally posted by BigDaddyLH
              Sometimes one's behaviour is punishment enough. I hope you like Color.PINK.
              That was Zen, a higher state of consciousness and all that.

              kind regards,

              Jos ;-)

              Comment

              • praclarush
                New Member
                • Oct 2007
                • 27

                #8
                Ya... Thanks for the info sorry I haven't replayed. I've been a little busy.

                Praclarush

                Comment

                Working...