Class DefaultListRenderer<E>

java.lang.Object
org.jdesktop.swingx.renderer.AbstractRenderer
org.jdesktop.swingx.renderer.DefaultListRenderer<E>
All Implemented Interfaces:
Serializable, ListCellRenderer<E>, UIDependent, StringValue, RolloverRenderer

public class DefaultListRenderer<E> extends AbstractRenderer implements ListCellRenderer<E>
Adapter to glue SwingX renderer support to core API. It has convenience constructors to create a LabelProvider, optionally configured with a StringValue and horizontal alignment. Typically, client code does not interact with this class except at instantiation time.

Note: core DefaultListCellRenderer shows either an icon or the element's toString representation, depending on whether or not the given value is of type icon or implementors. This renderer's empty/null provider constructor takes care of configuring the default provider with a converter which mimics that behaviour. When instantiating this renderer with any of the constructors which have converters as parameters, it's up to the client code to supply the appropriate converter, if needed:


 StringValue sv = new StringValue() {
 
     public String getString(Object value) {
         if (value instanceof Icon) {
             return "";
         }
         return StringValue.TO_STRING.getString(value);
     }
 
 };
 StringValue lv = new MappedValue(sv, IconValue.ICON);
 listRenderer = new DefaultListRenderer(lv, alignment);
 
 
Author:
Jeanette Winzenburg
See Also:
  • Field Details

  • Constructor Details

    • DefaultListRenderer

      public DefaultListRenderer()
      Instantiates a default list renderer with the default component provider.
    • DefaultListRenderer

      public DefaultListRenderer(ComponentProvider<?> componentProvider)
      Instantiates a ListCellRenderer with the given ComponentProvider. If the provider is null, creates and uses a default. The default provider is of type LabelProvider

      Note: the default provider is configured with a custom StringValue which behaves exactly as core DefaultListCellRenderer: depending on whether or not given value is of type icon or implementors, it shows either the icon or the element's toString.

      Parameters:
      componentProvider - the provider of the configured component to use for cell rendering
    • DefaultListRenderer

      public DefaultListRenderer(StringValue converter)
      Instantiates a default table renderer with a default component controller using the given converter.

      PENDING JW: how to guarantee core consistent icon handling? Leave to client code?

      Parameters:
      converter - the converter to use for mapping the content value to a String representation.
    • DefaultListRenderer

      public DefaultListRenderer(StringValue converter, int alignment)
      Instantiates a default list renderer with a default component controller using the given converter and horizontal alignment. PENDING JW: how to guarantee core consistent icon handling? Leave to client code?
      Parameters:
      converter - the converter to use for mapping the content value to a String representation.
      alignment - the horizontal alignment.
    • DefaultListRenderer

      public DefaultListRenderer(StringValue stringValue, IconValue iconValue)
      Instantiates a default list renderer with default component provider using both converters.
      Parameters:
      stringValue - the converter to use for the string representation
      iconValue - the converter to use for the icon representation
    • DefaultListRenderer

      public DefaultListRenderer(StringValue stringValue, IconValue iconValue, int alignment)
      Instantiates a default list renderer with default component provider using both converters and the given alignment.
      Parameters:
      stringValue - the converter to use for the string representation
      iconValue - the converter to use for the icon representation
      alignment - the rendering component's horizontal alignment
  • Method Details

    • getListCellRendererComponent

      public Component getListCellRendererComponent(JList<? extends E> list, E value, int index, boolean isSelected, boolean cellHasFocus)
      Returns a configured component, appropriate to render the given list cell.

      Note: The component's name is set to "List.cellRenderer" for the sake of Synth-based LAFs.

      Specified by:
      getListCellRendererComponent in interface ListCellRenderer<E>
      Parameters:
      list - the JList to render on
      value - the value to assign to the cell
      isSelected - true if cell is selected
      cellHasFocus - true if cell has focus
      index - the row index (in view coordinates) of the cell to render
      Returns:
      a component to render the given list cell.
    • createDefaultComponentProvider

      protected ComponentProvider<?> createDefaultComponentProvider()
      The default ComponentProvider to use if no special.
      Specified by:
      createDefaultComponentProvider in class AbstractRenderer
      Returns:
      the default ComponentProvider