public interface CellRenderer<T>
An instance of a renderer can be developed as such:
public class MyYesNoRenderer extends Label implements ListCellRenderer { public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected) { if( ((Boolean)value).booleanValue() ) { setText("Yes"); } else { setText("No"); } return this; } public Component getListFocusComponent(List list) { Label label = new label(""); label.getStyle().setBgTransparency(100); return label; } }
It is recommended that the component whose values are manipulated would not support features such as repaint(). This is accomplished by overriding repaint in the subclass with an empty implementation. This is advised for performance reasons, otherwise every change made to the component might trigger a repaint that wouldn't do anything but still cost in terms of processing.
GenericListCellRenderer
,
ListCellRenderer
Modifier and Type | Method and Description |
---|---|
Component |
getCellRendererComponent(Component list,
Object model,
T value,
int index,
boolean isSelected)
Deprecated.
Returns a component instance that is already set to render "value".
|
Component |
getFocusComponent(Component list)
Deprecated.
Returns a component instance that is painted under the currently focused renderer
and is animated to provide smooth scrolling.
|
Component getCellRendererComponent(Component list, Object model, T value, int index, boolean isSelected)
list
- the list componentmodel
- the model behind the rendervalue
- the value to renderindex
- the index in the listisSelected
- whether the entry is selectedComponent getFocusComponent(Component list)
list
- the parent listComponent.setSmoothScrolling(boolean)