This class extends SimpleStringConverter and leverages EnumUtil to provide a default formatting for enum values. It can also accept custom callbacks for more specific conversion requirements.
Usage Example:
Default usage with title case formatting:
ComboBox<MyEnum> comboBox = new ComboBox<>();
comboBox.setConverter(new EnumStringConverter<>());
Custom callback for specific formatting:
ComboBox<MyEnum> comboBox = new ComboBox<>();
comboBox.setConverter(new EnumStringConverter<>(myEnum -> "Custom format: " + myEnum.name()));
| Access | Constructor and Description |
|---|---|
| public | EnumStringConverter()
Converts an enum value to title case, replacing underscores with spaces and capitalizing the first letter of each word. |
| public | EnumStringConverter(Callback<T, String>
The callback to convert enum value to a String. valueToStringCallback)Constructor that accepts a custom callback for converting enum values to strings. |
| public | EnumStringConverter(Callback<T, String>
The callback to convert non-null enum value to a String. nonNullValueCallback, String The default String value to return if the enum value is null. nullDefaultValue)Constructor that accepts a custom callback for converting non-null enum values to strings and a default string to return if the enum value is null. |
| EnumStringConverter | back to summary |
|---|---|
| public EnumStringConverter() Converts an enum value to title case, replacing underscores with spaces and capitalizing the first letter of each word. If the enum value is null, returns an empty string. Example: 1. null -> "" Example: 2. MY_ENUM_VALUE -> My Enum Value | |
| EnumStringConverter | back to summary |
|---|---|
| public EnumStringConverter(Callback<T, String> valueToStringCallback) Constructor that accepts a custom callback for converting enum values to strings. The provided callback should handle conversion from enum value to String, including any necessary null handling. | |
| EnumStringConverter | back to summary |
|---|---|
| public EnumStringConverter(Callback<T, String> nonNullValueCallback, String nullDefaultValue) Constructor that accepts a custom callback for converting non-null enum values to strings and a default string to return if the enum value is null. | |