e774. 创建JList组件

Posted borter

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了e774. 创建JList组件相关的知识,希望对你有一定的参考价值。

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组件的主要内容,如果未能解决你的问题,请参考以下文章

e777. 获得JList组件的所有项

java和sql到JList

如何从 JList 中的组件中获取文本?

如何在Java Swing中创建响应式JList

e785. 监听JList中项的变动

e783. 监听对JList中项双击和三击