Package uk.ac.starlink.util.gui
Class CustomComboBoxRenderer<T>
java.lang.Object
uk.ac.starlink.util.gui.CustomComboBoxRenderer<T>
- All Implemented Interfaces:
ListCellRenderer<T>
Utility class which does the job of rendering items into a JComboBox
when you just want to provide a different stringification of them
than the one provided by the toString method.
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.
- Author:
- Mark Taylor (Starlink)
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a renderer for which nulls are represented as blank.CustomComboBoxRenderer
(String nullTxt) Constructs a renderer with a custom null representation. -
Method Summary
Modifier and TypeMethodDescriptiongetListCellRendererComponent
(JList<? extends T> list, T value, int index, boolean isSelected, boolean hasFocus) protected String
Turns a non-null object which might be found in the ComboBox itself into a string to be displayed by a standard combobox renderer.
-
Constructor Details
-
CustomComboBoxRenderer
public CustomComboBoxRenderer()Constructs a renderer for which nulls are represented as blank. -
CustomComboBoxRenderer
Constructs a renderer with a custom null representation.- Parameters:
nullTxt
- text to be displayed for null values
-
-
Method Details
-
getListCellRendererComponent
public Component getListCellRendererComponent(JList<? extends T> list, T value, int index, boolean isSelected, boolean hasFocus) - Specified by:
getListCellRendererComponent
in interfaceListCellRenderer<T>
-
mapValue
Turns a non-null object which might be found in the ComboBox itself into a string to be displayed by a standard combobox renderer. The default implementation just uses the toString method.This method will only be invoked if
value
is not null. In case of null, thenullTxt
value supplied at construction tim will be used instead.- Parameters:
value
- non-null value to map- Returns:
- display string
-