Class ListPanel<T>

Type Parameters:
T - Any class you like, as long as it has a sensible toString()
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class ListPanel<T> extends JPanel
Presents a vertical JList of items, with an optional header label above the list, and an optional list of command buttons under the list. This was intended specifically for use on the ExtensionManagerDialog, but is generic enough to use for any type of object. You can listen for list selection events, and your list of custom commands (if supplied) can be any AbstractAction.

The ListPanel defaults to an initial pixel width of 200, but you can change this with setPreferredWidth(). The command buttons (if specified) will grow horizontally to fill the width of the ListPanel.

Since:
swing-extras 2.5
Author:
scorbo2
See Also:
  • Constructor Details

    • ListPanel

      public ListPanel()
      Creates an empty ListPanel with no header label and no custom commands.
    • ListPanel

      public ListPanel(String title)
      Creates an empty ListPanel with the given header label.
    • ListPanel

      public ListPanel(List<AbstractAction> commands)
      Creates an empty ListPanel with no header label and with the given list of custom commands.
    • ListPanel

      public ListPanel(String headerLabel, List<AbstractAction> commands)
      Creates an empty ListPanel with the given header label and the given list of custom commands.
  • Method Details

    • clear

      public void clear()
    • getItemAt

      public T getItemAt(int index)
    • removeItemAt

      public void removeItemAt(int index)
    • setPreferredWidth

      public void setPreferredWidth(int width)
    • setPreferredSize

      public void setPreferredSize(Dimension dim)
      Overrides:
      setPreferredSize in class JComponent
    • setListCellRenderer

      public void setListCellRenderer(ListCellRenderer<T> renderer)
    • getPreferredSize

      public Dimension getPreferredSize()
      Overridden here to force correct sizing when this ListPanel is added to a BorderLayout in the EAST or WEST positions. BorderLayout is a bit wonky and returning my own preferredWidth was the only way I could find to force it to render this ListPanel at the desired size, as opposed to just auto-sizing it based on its contents, which is what it will do without this override.
      Overrides:
      getPreferredSize in class JComponent
    • isEmpty

      public boolean isEmpty()
    • getItemCount

      public int getItemCount()
    • getSelected

      public T getSelected()
    • selectItem

      public void selectItem(int index)
    • getAll

      public List<T> getAll()
    • setItems

      public void setItems(List<T> extensions)
    • addItems

      public void addItems(List<T> extensions)
    • addItem

      public void addItem(T extension)
    • addListSelectionListener

      public void addListSelectionListener(ListSelectionListener listener)
    • removeListSelectionListener

      public void removeListSelectionListener(ListSelectionListener listener)