Populating Swing JComboBox from Enum

Viewed 40232

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!

4 Answers

This can also be achieved using only the default constructor and without using setModel() method:

JComboBox<Mood> comboBox_mood = new JComboBox<>();
Related