首页 > 其他 > 详细

e774. 创建JList组件

时间:2018-09-06 10:32:47      阅读:157      评论:0      收藏:0      [点我收藏+]

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组件

原文:https://www.cnblogs.com/borter/p/9596132.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!