Class EnumComboBox<E extends Enum<E>>

Type Parameters:
E - the enum type
All Implemented Interfaces:
ActionListener, ImageObserver, ItemSelectable, MenuContainer, Serializable, EventListener, Accessible, ListDataListener

public class EnumComboBox<E extends Enum<E>> extends JComboBox<E>
A JComboBox backed directly by enum values, with optional extra choice (e.g. "Any" or "None") and customizable labels.
See Also:
  • Constructor Details

    • EnumComboBox

      public EnumComboBox(Class<E> enumType)
      Create a combo box that lists all constants of the given enum type, using Enum.name() as the label.
      Parameters:
      enumType - the enum class
    • EnumComboBox

      public EnumComboBox(Class<E> enumType, E defaultChoice, String extraChoiceLabel, Function<E,String> labelProvider)
      Create a combo box that lists all constants of the given enum type, with an optional extra choice (e.g. "Any"), a default selection, and a custom label provider.
      Parameters:
      enumType - the enum class
      defaultChoice - the default selected enum constant, or null to select the extra choice if present
      extraChoiceLabel - label for a non-enum choice at the top, or null for none
      labelProvider - function mapping enum constants to display labels
    • EnumComboBox

      public EnumComboBox(Class<E> enumType, String extraChoiceLabel, Function<E,String> labelProvider)
      Create a combo box that lists all constants of the given enum type, with an optional extra choice (e.g. "Any") and a custom label provider.
      Parameters:
      enumType - the enum class
      extraChoiceLabel - label for a non-enum choice at the top, or null for none
      labelProvider - function mapping enum constants to display labels
  • Method Details

    • getSelectedEnum

      public E getSelectedEnum()
      Get the selected enum value. Returns null if the extra choice was used and is selected.
      Returns:
      the selected enum value, or null for the extra choice