public class CustomComboBoxRenderer<T> extends Object implements ListCellRenderer<T>
You would use this class by providing an implementation of the
mapValue(T)
method and class by calling
JComboBox.setRenderer(javax.swing.ListCellRenderer<? super E>)
on an instance of the resulting
subclass.
Constructor and Description |
---|
CustomComboBoxRenderer()
Constructs a renderer for which nulls are represented as blank.
|
CustomComboBoxRenderer(String nullTxt)
Constructs a renderer with a custom null representation.
|
Modifier and Type | Method and Description |
---|---|
Component |
getListCellRendererComponent(JList<? extends T> list,
T value,
int index,
boolean isSelected,
boolean hasFocus) |
protected String |
mapValue(T value)
Turns a non-null object which might be found in the ComboBox itself
into a string to be displayed by a standard combobox renderer.
|
public CustomComboBoxRenderer()
public CustomComboBoxRenderer(String nullTxt)
nullTxt
- text to be displayed for null valuespublic Component getListCellRendererComponent(JList<? extends T> list, T value, int index, boolean isSelected, boolean hasFocus)
getListCellRendererComponent
in interface ListCellRenderer<T>
protected String mapValue(T value)
This method will only be invoked if value
is not null.
In case of null, the nullTxt
value supplied at construction
tim will be used instead.
value
- non-null value to mapCopyright © 2024 Central Laboratory of the Research Councils. All Rights Reserved.