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.getComboB ox("colorC omboBox");
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);
}
JComboBox combo = (JComboBox)panel.getComboB
for( int i = 0; i < COLOR_MAP.size(); i++ )
combo.insertItemAt(??????,
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_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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
for( String key : COLOR_MAP.keySet() )
combo.insertItemAt(key, i);
there is no "i" in this =)
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);
if u just want the combo poluated with the keyt then use the latter
> there is no "i" in this =)
combo.addItem(key);
ASKER
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?
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.back ground");
ASKER
UIManager.get("Button.back ground");
how do I use this?
how do I use this?
ASKER
using:
this.setBackground((Color) UIManager. get("Butto n.backgrou nd"));
it sets all the buttons to white instead of the default cream color
this.setBackground((Color)
it sets all the buttons to white instead of the default cream color
Color defaultColour = (Color) UIManager.get("Button.back ground");
> it sets all the buttons to white instead of the default cream color
thats probably the look and feel you're using overriding things
thats probably the look and feel you're using overriding things
ASKER
ok, so how do I get the default
ASKER
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().getBackgroundCol or();
Color bg = new JButton().getBackgroundCol
ASKER
setBackground(new JButton().getBackground()) ;
= all white buttons......NOOOOOOoooooo oooo!!!!!! !!!....... ..
= all white buttons......NOOOOOOoooooo
what is it u are trying to achieve??
ASKER
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 =(
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 =(
ASKER
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
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.
the only way for the colour to change is if you are changing it.
ASKER
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.k eySet()));
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
> is there any other way to change a buttons colour than SetBackground? cus I searched the prject for that.... =P
nope
nope
ASKER
Thanks guys, my new problem is another topic =)
:-)
ASKER
btw, I found out how to get the default color back:
setBackground(null);
setBackground(null);
ASKER