views:

673

answers:

2

I would like to populate a java.swing JComboBox with values from an Enum.

e.g.

public enum Mood { HAPPY, SAD, AWESOME; }

and have these three values populate a readonly JComboBox.

Thanks!

+3  A: 

try:

new JComboBox(Mood.values());
Pierre
A: 

The solution proposed by @Pierre is good. Usually you use a DefaultComboBoxModel or a ComboBoxModel or bindings to the ComboBoxModel for more complex stuff.

By default a JComboBox is not editable.

John Doe