colored JComboBox items?

Discussion in 'Java' started by Ian, Apr 13, 2004.

  1. Ian

    Ian Guest

    Hi,
    Is it possible to have a jcombobox with the items being actual colors(or at
    leat the fonts) eg.

    String[] myColors = { "Red", "Blue", "Yellow", "Orange", "White" };

    JComboBox colorList = new JComboBox(myColors);

    colorList.addActionListener(this);

    But when the user clicks on the combobox instead of the names of the colors
    being dislpayed each item is the appropriate color
    Any help appreciated
    Ian, Apr 13, 2004
    #1
    1. Advertising

  2. Ian

    Chris Smith Guest

    Ian wrote:
    > Is it possible to have a jcombobox with the items being actual colors(or at
    > leat the fonts) eg.
    >
    > String[] myColors = { "Red", "Blue", "Yellow", "Orange", "White" };
    >
    > JComboBox colorList = new JComboBox(myColors);
    >
    > colorList.addActionListener(this);
    >
    > But when the user clicks on the combobox instead of the names of the colors
    > being dislpayed each item is the appropriate color


    This is what cell renderers are for. See the setRenderer method of
    JComboBox.

    --
    www.designacourse.com
    The Easiest Way to Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
    Chris Smith, Apr 13, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Franck
    Replies:
    5
    Views:
    442
    intrader
    Jun 27, 2005
  2. JM
    Replies:
    2
    Views:
    3,524
    Bruce Barker
    Sep 21, 2005
  3. markus brosch

    [java2D] colored gradient

    markus brosch, Aug 18, 2003, in forum: Java
    Replies:
    7
    Views:
    877
    markus brosch
    Aug 19, 2003
  4. gajo
    Replies:
    2
    Views:
    919
    Roedy Green
    May 10, 2004
  5. Brian Tozer

    Semi-opaque colored background

    Brian Tozer, Feb 8, 2004, in forum: HTML
    Replies:
    11
    Views:
    4,782
    Steve Pugh
    Feb 9, 2004
Loading...

Share This Page