1. 程式人生 > >e774. 創建JList組件

e774. 創建JList組件

color call some int strong objects pre sele example

By default, a list allows more than one item to be selected. Also, the selected items need not be contiguous. To change this default, see e781 設置JList中的選擇模式.

A list selection event is fired when the set of selected items is changed (see e784 監聽對JList選擇變動).

    // Create a list with some items
    String[] items = {"A", "B", "C", "D"
}; JList list = new JList(items);

The items can be arbitrary objects. The toString() method of the objects is displayed in the list component.

    // Create a list with two items - "123" and "Sun May 19 21:15:38 PDT 2002"
    Object[] items2 = {new Integer(123), new java.util.Date()};
    list = new JList(items2);

By default, a list does not automatically display a scrollbar when there are more items than can be displayed. The list must be wrapped in a scroll pane:

    JScrollPane scrollingList = new JScrollPane(list);

Related Examples

e774. 創建JList組件