Class GListCellRenderer<E>

Type Parameters:
E - the element-type this list models.
All Implemented Interfaces:
GComponent, ImageObserver, MenuContainer, PropertyChangeListener, Serializable, EventListener, Accessible, ListCellRenderer<E>, SwingConstants
Direct Known Subclasses:
GComboBoxCellRenderer

public class GListCellRenderer<E> extends AbstractGCellRenderer implements ListCellRenderer<E>
Provides a common implementation of a list renderer, for use in both JList and JComboBox.

HTML rendering defaults to disabled. See GComponent.setHTMLRenderingEnabled(boolean).

See Also:
  • Constructor Details

    • GListCellRenderer

      public GListCellRenderer()
      Constructs a new GListCellRenderer.
  • Method Details

    • createDefaultTextRenderer

      public static <E> GListCellRenderer<E> createDefaultTextRenderer(Function<E,String> cellToTextMappingFunction)
      Returns a new ListCellRenderer that maps the list's data instance to a string used in the cell.

      Use this if you only need to provide a way to get the string value from the type being shown in the list.

      Parameters:
      cellToTextMappingFunction - a function that maps your custom type to a string value
      Returns:
      new GListCellRenderer instance
    • getDefaultBackgroundColor

      protected Color getDefaultBackgroundColor()
      Overrides:
      getDefaultBackgroundColor in class AbstractGCellRenderer
    • getItemText

      protected String getItemText(E value)
      Return the cell renderer text
      Parameters:
      value - Cell object value
      Returns:
      A string interpretation of value; generated by calling value.toString()
    • getListCellRendererComponent

      public Component getListCellRendererComponent(JList<? extends E> list, E value, int index, boolean isSelected, boolean hasFocus)
      Specified by:
      getListCellRendererComponent in interface ListCellRenderer<E>
    • setForegroundColor

      protected void setForegroundColor(JList<? extends E> list, ListModel<? extends E> model, Object value)
    • configureFont

      protected void configureFont(JList<? extends E> list, ListModel<? extends E> model, int index)