Class RenderingComboBox<E>

All Implemented Interfaces:
ActionListener, ImageObserver, ItemSelectable, MenuContainer, Serializable, EventListener, Accessible, ListDataListener, ListCellRenderer<E>

public class RenderingComboBox<E> extends JComboBox<E> implements ListCellRenderer<E>
JComboBox with custom renderer. This convenience class allows you to do your own rendering without having to provide an actual implementation of ListCellRenderer, which is mildly fiddly. Just override getRendererText(E) and/or getRendererIcon(E).
Since:
12 Jan 2006
Author:
Mark Taylor
See Also:
  • Constructor Details

    • RenderingComboBox

      protected RenderingComboBox(ComboBoxModel<E> model)
      Constructs a new combo box with a given model.
      Parameters:
      model - data model
    • RenderingComboBox

      protected RenderingComboBox(E[] items)
      Constructs a new combo box containing some supplied items.
      Parameters:
      items - initial selection of items
    • RenderingComboBox

      protected RenderingComboBox()
      Constructs a new combo box with a default data model.
  • Method Details

    • getRendererText

      protected String getRendererText(E item)
      Returns the text label to use to represent a given item. The default implementation just uses toString.
      Parameters:
      item - item
      Returns:
      textual label for item
    • getRendererIcon

      protected Icon getRendererIcon(E item)
      Returns an icon to use to represent a given item. The default implementation returns null.
      Parameters:
      item - item
      Returns:
      graphic label for item
    • getListCellRendererComponent

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