Class GListCellRenderer<E>

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

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

    • createDefaultCellTextRenderer

      public static <E> GListCellRenderer<E> createDefaultCellTextRenderer(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
    • 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)
    • computePlainTextListCellDimensions

      public Dimension computePlainTextListCellDimensions(JList<? extends E> list, List<E> items, int minWidth, int minHeight)
      Returns the width, height necessary to display the largest element in this list.

      Useful for setting a JList's fixed cell width and height to the actual necessary size.

      NOTE: the items and the renderer must be in plain text mode, not HTML rendering mode.

      Parameters:
      list - the JList that uses this cell renderer
      items - the items to measure
      minWidth - the minimum width that can be returned
      minHeight - the minimum height that can be returned
      Returns:
      a new Dimension containing a width and height value necessary to display the largest element in the list