Link to home
Start Free TrialLog in
Avatar of galneweinhaw
galneweinhaw

asked on

Insert the keys in a map into a combobox

Using my color map below, I want to insert the keys into a combo box.... how?

            JComboBox combo = (JComboBox)panel.getComboBox("colorComboBox");
            for( int i = 0; i < COLOR_MAP.size(); i++ )
                  combo.insertItemAt(??????, i);      


    public static final Map<String, Color> COLOR_MAP = new HashMap<String, Color>();

    static {
      COLOR_MAP.put("black", Color.BLACK);
      COLOR_MAP.put("blue", Color.BLUE);
      COLOR_MAP.put("cyan", Color.CYAN);
      COLOR_MAP.put("darkgray", Color.DARK_GRAY);
      COLOR_MAP.put("gray", Color.GRAY);
      COLOR_MAP.put("green", Color.GREEN);
      COLOR_MAP.put("lightgray", Color.LIGHT_GRAY);
      COLOR_MAP.put("magenta", Color.MAGENTA);
      COLOR_MAP.put("orange", Color.ORANGE);
      COLOR_MAP.put("pink", Color.PINK);
      COLOR_MAP.put("red", Color.RED);
      COLOR_MAP.put("white", Color.WHITE);
      COLOR_MAP.put("yellow", Color.YELLOW);
    }
SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of galneweinhaw
galneweinhaw

ASKER

which is more efficient?
         for( String key : COLOR_MAP.keySet() )
               combo.insertItemAt(key, i);    

there is no "i" in this =)
> which is more efficient?

if u just want the combo poluated with the keyt then use the latter

> there is no "i" in this =)

 combo.addItem(key);    
last followup =)

what do you use to get the "default" os/skin button colour?
is there a "nocolor" option or something similar I can add to the map?
UIManager.get("Button.background");
UIManager.get("Button.background");

how do I use this?
using:
this.setBackground((Color)UIManager.get("Button.background"));

it sets all the buttons to white instead of the default cream color
Color defaultColour = (Color) UIManager.get("Button.background");

> it sets all the buttons to white instead of the default cream color

thats probably the look and feel you're using overriding things
ok, so how do I get the default
there is no look and feel, it's just all defaults untill I changed the colors...now I can't get them back =(
theres always a look and feel :)
this will tell u the default color being used :)

Color bg = new JButton().getBackgroundColor();
setBackground(new JButton().getBackground());

= all white buttons......NOOOOOOoooooooooo!!!!!!!!!.........
what is it u are trying to achieve??
I just want to set a button to the default color scheme so it goes along with everything else (which for me is a creamy gray)

right now I have some white buttons beside all sorts of other default coloured controls, and I can't get the white buttons to go back =(
white or red or whatever I set them too.

but if I comment out the setbackground line....they still show up white or red ro whatever, like they've saved their color
if you don't set the button colour then they will be the default colour :)
the only way for the colour to change is if you are changing it.
is there any other way to change a buttons colour than SetBackground? cus I searched the prject for that.... =P
combo.setModel(new Vector<String>(COLOR_MAP.keySet()));
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
> is there any other way to change a buttons colour than SetBackground? cus I searched the prject for that.... =P

nope
Thanks guys, my new problem is another topic =)
:-)
btw, I found out how to get the default color back:

setBackground(null);