Class ListPanel<T>

Type Parameters:
T - The type for the items in this list
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class ListPanel<T> extends JPanel
This class provides a panel that contains a JList component.
See Also:
  • Constructor Details

    • ListPanel

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

    • setSelectionMode

      public void setSelectionMode(int selectionMode)
      Sets the selection mode for the list. See JList for allowed Selection modes
      Parameters:
      selectionMode - the selectionMode to use.
    • setListTitle

      public void setListTitle(String listTitle)
      Places a title just above the scrolling list.
      Parameters:
      listTitle - the title to use.
    • addListSelectionListener

      public void addListSelectionListener(ListSelectionListener listener)
      Parameters:
      listener - the listener to add
    • removeListSelectionListener

      public void removeListSelectionListener(ListSelectionListener listener)
      Parameters:
      listener - the listener to remove
    • isSelectionEmpty

      public boolean isSelectionEmpty()
      Returns true if no list items are selected.
      Returns:
      true if no list items are selected.
    • getSelectedValue

      public T getSelectedValue()
      Returns the first selected value in the list or null if nothing is selected.
      Returns:
      the first selected value in the list or null if nothing is selected.
    • getSelectedIndex

      public int getSelectedIndex()
      Get the index of the selected item in the list.
      Returns:
      the index of the selected item in the list.
    • setSelectedIndex

      public void setSelectedIndex(int i)
      Select the item at the given index.
      Parameters:
      i - the index at which to get the item.
    • setSelectedValue

      public void setSelectedValue(T item)
      Selects the item.
      Parameters:
      item - the item to select
    • getSelectedValues

      public List<T> getSelectedValues()
      Returns an array of all the selected items.
      Returns:
      an array of all the selected items.
    • refreshList

      public void refreshList(T[] dataList)
      replaces the list contents with the new list.
      Parameters:
      dataList - the new list for the contents.
    • setListData

      public void setListData(T[] data)
      Sets the list data
      Parameters:
      data - the data
    • setListModel

      public void setListModel(ListModel<T> listModel)
      Sets a list model for the internal list to use.
      Parameters:
      listModel - the list model to use.
    • getListModel

      public ListModel<T> getListModel()
      Get the list model for the list.
      Returns:
      the list model for the list.
    • getList

      public JList<T> getList()
      Return the JList component.
      Returns:
      the JList component.
    • setCellRenderer

      public void setCellRenderer(ListCellRenderer<T> r)
      Get the cell renderer for the list.
      Parameters:
      r - the cell renderer to use.
    • setListSelectionListener

      public void setListSelectionListener(ListSelectionListener listener)
      Sets the listener to be notified when the selection changes.
      Parameters:
      listener - the Listener to be notified. If listener can be null, which means no one is to be notified.
    • setDoubleClickActionListener

      public final void setDoubleClickActionListener(ActionListener listener)
      Sets the listener to be notified whenever a list item is doubleClicked.
      Parameters:
      listener - the Listener to be notified. If listener can be null, which means no one is to be notified.
    • setMouseListener

      public void setMouseListener(MouseListener l)
      Set the mouse listener for the list.
      Parameters:
      l - the mouse listener to set.
    • setKeyListener

      public void setKeyListener(KeyListener l)
    • issueWarning

      public void issueWarning()
      Displays a standard warning message about no selected objects in the list.
    • issueWarning

      public void issueWarning(String msg, String title)
      Displays any warning message.
      Parameters:
      msg - the warning message to display.
      title - the title of the dialog to display.
    • ensureIndexIsVisible

      public void ensureIndexIsVisible(int index)
      Scroll viewport such that the index is visible.
      Parameters:
      index - the index of the item in the list to make visible.
    • main

      public static void main(String[] args)
      Simple test for ListPanel class.
      Parameters:
      args - test args not used