Saturday, 17 August 2013

Adding Multiple Enums to JComboBox

Adding Multiple Enums to JComboBox

I want to add different Enums to a single JComboBox. Here is how the code
looks like. Type contains 3 different type of Enums(Colors, Shapes,
Dimensions).
final JComboBox typeJComboBox = new JComboBox(Type.Colors.values());
for(Type.Shapes shape: Type.Shapes.values()) {
typeJComboBox .addItem(shape);
}
for(Type.Dimensions dimension : Type.Dimensions.values()) {
typeJComboBox .addItem(dimension );
}
What generic type do I use? When using eclipse, there is a yellow squiggly
line under JComboBox and when you hover your mouse over it, it says "Infer
Generic Type Arguments...".

No comments:

Post a Comment