This converter is typically used to format objects as strings for display purposes, with optional
handling for null values. The conversion from string back to object is not usually required,
hence the fromString(String) method returns null.
Usage Example:
Before using SimpleStringConverter:
comboBox.setConverter(new StringConverter<>() {
@Override
public String toString(Status status) {
if (status != null) {
return status.getDescription();
}
return "";
}
@Override
public Status fromString(String string) {
return null;
}
});
After using SimpleStringConverter:
comboBox.setConverter(new SimpleStringConverter<>(Status::getDescription, ""));
| Access | Constructor and Description |
|---|---|
| public | SimpleStringConverter()
Creates a new
|
| public | SimpleStringConverter(Callback<T, String>
the callback to convert a non-null value to a String valueToStringCallback)Creates a new |
| public | SimpleStringConverter(Callback<T, String>
The callback to convert a non-null value to a String. nonNullValueCallback, String The default String value to return if the value is null. nullDefaultValue)Constructor that automatically handles null values by returning a default null value string. |
| Modifier and Type | Method and Description |
|---|---|
| public T | Returns: always returns null.the string to be converted to an object. s)Implements abstract javafx. This method is not implemented and always returns null. |
| public String | toString(T object)
Implements abstract javafx. Converts the object provided into its string form. |
| valueToStringCallback | back to summary |
|---|---|
| private final Callback<T, String> valueToStringCallback | |
| SimpleStringConverter | back to summary |
|---|---|
| public SimpleStringConverter() Creates a new
| |
| SimpleStringConverter | back to summary |
|---|---|
| public SimpleStringConverter(Callback<T, String> valueToStringCallback) Creates a new
| |
| SimpleStringConverter | back to summary |
|---|---|
| public SimpleStringConverter(Callback<T, String> nonNullValueCallback, String nullDefaultValue) Constructor that automatically handles null values by returning a default null value string.
| |
| fromString | back to summary |
|---|---|
| public T fromString(String s) Implements abstract javafx. This method is not implemented and always returns null. Since the primary use of this converter is to display objects as strings in the UI, converting strings back to objects is not required. Therefore, this method simply returns null. | |
| toString | back to summary |
|---|---|
| public String toString(T object) Implements abstract javafx. Doc from javafx. Converts the object provided into its string form. Format of the returned string is defined by the specific converter.
| |