Package uk.ac.starlink.util.gui
Class CustomComboBoxRenderer
- java.lang.Object
-
- uk.ac.starlink.util.gui.CustomComboBoxRenderer
-
- All Implemented Interfaces:
javax.swing.ListCellRenderer
public class CustomComboBoxRenderer extends java.lang.Object implements javax.swing.ListCellRenderer
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(java.lang.Object)
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()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.awt.Component
getListCellRendererComponent(javax.swing.JList list, java.lang.Object value, int index, boolean isSelected, boolean hasFocus)
java.lang.Object
getNullRepresentation()
Returns the representation for the null value.protected java.lang.Object
mapValue(java.lang.Object value)
Turns an object which might be found in the ComboBox itself into an object that can be rendered by a standard combobox renderer.void
setNullRepresentation(java.lang.Object nullRep)
Sets the representation for the null value.
-
-
-
Method Detail
-
getListCellRendererComponent
public java.awt.Component getListCellRendererComponent(javax.swing.JList list, java.lang.Object value, int index, boolean isSelected, boolean hasFocus)
- Specified by:
getListCellRendererComponent
in interfacejavax.swing.ListCellRenderer
-
setNullRepresentation
public void setNullRepresentation(java.lang.Object nullRep)
Sets the representation for the null value. If set to a non-null value, this will be used to render a null; otherwise,mapValue(java.lang.Object)
will be called as usual (which may itself do something with the null).- Parameters:
nullRep
- null representation
-
getNullRepresentation
public java.lang.Object getNullRepresentation()
Returns the representation for the null value.- Returns:
- null representation
-
mapValue
protected java.lang.Object mapValue(java.lang.Object value)
Turns an object which might be found in the ComboBox itself into an object that can be rendered by a standard combobox renderer. Typically the return value of this method would be a String more suitable than the result of value's toString method.The default implementation just returns the value itself
- Parameters:
value
- value to map- Returns:
- value to map it into (probably a string)
-
-