Package uk.ac.starlink.util.gui
Class CustomComboBoxRenderer<T>
- java.lang.Object
-
- uk.ac.starlink.util.gui.CustomComboBoxRenderer<T>
-
- All Implemented Interfaces:
javax.swing.ListCellRenderer<T>
public class CustomComboBoxRenderer<T> extends java.lang.Object implements javax.swing.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 callingJComboBox.setRenderer(javax.swing.ListCellRenderer<? super E>)
on an instance of the resulting subclass.- Author:
- Mark Taylor (Starlink)
-
-
Constructor Summary
Constructors Constructor Description CustomComboBoxRenderer()
Constructs a renderer for which nulls are represented as blank.CustomComboBoxRenderer(java.lang.String nullTxt)
Constructs a renderer with a custom null representation.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.awt.Component
getListCellRendererComponent(javax.swing.JList<? extends T> list, T value, int index, boolean isSelected, boolean hasFocus)
protected java.lang.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.
-
-
-
Constructor Detail
-
CustomComboBoxRenderer
public CustomComboBoxRenderer()
Constructs a renderer for which nulls are represented as blank.
-
CustomComboBoxRenderer
public CustomComboBoxRenderer(java.lang.String nullTxt)
Constructs a renderer with a custom null representation.- Parameters:
nullTxt
- text to be displayed for null values
-
-
Method Detail
-
getListCellRendererComponent
public java.awt.Component getListCellRendererComponent(javax.swing.JList<? extends T> list, T value, int index, boolean isSelected, boolean hasFocus)
- Specified by:
getListCellRendererComponent
in interfacejavax.swing.ListCellRenderer<T>
-
mapValue
protected java.lang.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. 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
-
-