Default implementation of
CellListCellRenderer
. Renders a
cell to look like a horizontally
centered label, with caption below the icon, except
that the selection background and focus indicator are restricted to
the text part of the label.
Works best with list whose elements implement the interface
CellListCellValue
.
Extension classes override method
prepare
to
determine what text and what icon should be displayed.
getBorderSelectionColor
public Color getBorderSelectionColor()
Return the color which is used to draw the focus indicator.
getFont
public Font getFont()
Return the font used for the caption.
getForeground
public Color getForeground()
The color which is used to display the caption.
- Value of property foreGround.
getIcon
public Icon getIcon()
Icon to be displayed.
getIconBackground
public Color getIconBackground()
Return the background color for icons.
- Value of property iconBackground.
getIconTextGap
public int getIconTextGap()
Return the gap between text and icon
getInsets
public Insets getInsets()
Return the insets of this cell.
getSelectionBackground
public Color getSelectionBackground()
Return the background color for selections.
- Value of property selectionBackground.
getSelectionForeground
public Color getSelectionForeground()
Return the text color for selections.
- Value of property selectionForeground.
getText
public String getText()
Return the caption to be displayed.
paintElement
public void paintElement(Graphics2D g2,
CellList list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus)
The element is painted to look like a horizontally
centered label, with caption below the icon, except
that the selection background and focus indicator are restricted to
the text part of the label.
This implementation first calls
prepare
to initialize
the text and icon property from the value parameter. Extensions
of this class are advised to override
prepare
instead of this method.
- paintElement in interface CellListCellRenderer
prepare
protected void prepare(CellList list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus)
Prepare the renderer so that the given element can be displayed.
Extensions of this class should override this method (rather
than
paintElement
)
to set the correct text and icon.
This implementation distinguishes three cases:
- If
value
is of type CellListCellValue
,
icon and text
are set according to the information provided by that interface.
- Otherwise, if
value
is of type Icon
, that
icon is used, without text caption. - Otherwise, no icon is displayed and the text is set to
value.toString().
list
- The cell list to which the element belongsvalue
- The corresponding value returned from the modelindex
- The index of the cell in the listisSelected
- True if the specified cell was selected.cellHasFocus
- True if the specified cell has the focus.
setBorderSelectionColor
public final void setBorderSelectionColor(Color borderSelectionColor)
Set the color which is used to draw the focus indicator.
setFont
public final void setFont(Font font)
Set the font used for the caption.
setForeground
public final void setForeground(Color foreground)
Set the color to be used for the caption.
foreground
- New value of property foreGround.
setIcon
public void setIcon(Icon icon)
Set the icon to be displayed.
icon
- New value of property icon.
setIconBackground
public final void setIconBackground(Color iconBackground)
Set the background color for icons.
iconBackground
- New value of property iconBackground.
setIconTextGap
public void setIconTextGap(int iconTextGap)
Set the gap between text and icon
setInsets
public final void setInsets(Insets insets)
Set the insets of this cell.
setSelectionBackground
public final void setSelectionBackground(Color selectionBackground)
Set the background color for selections.
selectionBackground
- New value of property selectionBackground.
setSelectionForeground
public final void setSelectionForeground(Color selectionForeground)
Set the text color for selections.
selectionForeground
- New value of property selectionForeground.
setText
public void setText(String text)
Set the caption to be displayed.