The following methods return the indices of the selected items:

    // To create a list, see e774 创建JList组件

    // Get the index of all the selected items
int[] selectedIx = list.getSelectedIndices(); // Get all the selected items using the indices
for (int i=0; i<selectedIx.length; i++) {
Object sel = list.getModel().getElementAt(selectedIx[i]);
} // Get the index of the first selected item
int firstSelIx = list.getSelectedIndex(); // Get the index of the last selected item
int lastSelIx = list.getMaxSelectionIndex(); // Determine if the third item is selected
int index = 2;
boolean isSel = list.isSelectedIndex(index); // Determine if there are any selected items
boolean anySelected = !list.isSelectionEmpty();

The following methods return the selected item objects:

    // Get the first selected item
Object firstSel = list.getSelectedValue(); // Get all selected items without using indices
Object[] selected = list.getSelectedValues();
Related Examples

e779. 获得JList中的已选项的更多相关文章

  1. e780. 设置JList中的已选项

    List selection events are fired when the following methods are used to change the set of selected it ...

  2. vue table中使用多选的问题(翻页后如何保存已选项),联动echarts图表实现流量监控

    流量监控项目需求: 根据表格数据,添加多选功能,默认全选,根据已选项更新图表视图 1.表格需要多选 2.要联动图表,所以关键是要利用表格多选的触发回调函数 vue table中使用多选: 很简单,只需 ...

  3. OJ提交题目中的语言选项里G++与C++的区别(转)

    G++? 首先更正一个概念,C++是一门计算机编程语言,G++不是语言,是一款编译器中编译C++程序的命令而已. 那么他们之间的区别是什么? 在提交题目中的语言选项里,G++和C++都代表编译的方式. ...

  4. OJ提交题目中的语言选项里G++与C++的区别(转载)

    原文链接:http://blog.polossk.com/201405/c-plus-plus-g-plus-plus G++? 首先更正一个概念,C++是一门计算机编程语言,G++不是语言,是一款编 ...

  5. Linux: 介绍make menuconfig中的每个选项含义【转】

    转自:http://blog.csdn.net/gaoyuanlinkconcept/article/details/8810468 介绍make menuconfig中的每个选项含义 Linux 2 ...

  6. 【转】OJ提交题目中的语言选项里G++与C++的区别

    原文链接:http://blog.polossk.com/201405/c-plus-plus-g-plus-plus G++? 首先更正一个概念,C++是一门计算机编程语言,G++不是语言,是一款编 ...

  7. 修改 /var/lib/locales/supported.d/local 文件(使用 locale -a 命令查看系统中所有已配置的 locale)

    转自:http://zyxhome.org/wp/cc-prog-lang/c-stdlib-setlocale-usage-note/ http://www.west263.com/info/htm ...

  8. OJ提交题目中的语言选项里G++与C++的区别

    一.OJ提交题目中的语言选项里G++与C++的区别 http://www.th7.cn/Program/cp/201405/199001.shtml 首先更正一个概念,C++是一门计算机编程语言,G+ ...

  9. ubuntu中查看已安装软件包的方法

    ubuntu中查看已安装软件包的方法: 方法一:在新立得软件包管理器中,打到已安装,便可以看看有多少包被安装. 如果想把这些包的信息复制到一文件里,可用下面的方法. 方法二:在终端输入 sudo dp ...

随机推荐

  1. Fetch API 接口参考

    前言 Fetch API是新的ajax解决方案,用于解决古老的XHR对象不能实现的问题,Fetch API 提供了一个获取资源的接口(包括跨域请求),任何使用过 XMLHttpRequest 的人都能 ...

  2. [Windows Azure] Windows Azure Storage & SQL Database

    http://channel9.msdn.com/Series/Windows-Azure-Storage-SQL-Database-Tutorials Windows Azure offers mu ...

  3. C++11 delete和default

    Defaulted 函数 C++ 的类有四个特殊成员函数,它们分别是:默认构造函数.析构函数.拷贝构造函数以及拷贝赋值运算符.这些类的特殊成员函数负责创建.初始化.销毁,或者拷贝类的对象. 如果程序员 ...

  4. [翻译] Dremel made simple with Parquet

    首先自己的 blog 好久没有写技术相关的东西了,今天又动笔了,好高兴!然后转载请注明出处.最后开始正题: 原文:Dremel made simple with Parquet | Twitter E ...

  5. sql随机查询数据order by newid()

    方法1:最普通的写法,性能慢 ID,name FROM dt_keyword ORDER BY NEWID() 方法2:性能还可以 //先给数据库增加一列ALTER TABLE dt_keyword ...

  6. Android库分析工具(崩溃反编译)

    [时间:2016-07] [状态:Open] [关键词:android, 动态库,静态库, 编译,crash,addr2line] 本文主要整理Android编译系统中可用的库分析工作,可作为后续代码 ...

  7. Natural Language Processing, 2017, Mar.29, Weekly Report

    Distributed Representations of Words and Phrases and their Compositionality T Mikolov, I Sutskever, ...

  8. vps 切换内核

    一.安装内核aptitude install linux-image-3.13.0-24-generic linux-headers-3.13.0-24-generic 二.查看已安装的内核dpkg ...

  9. JAVA-数据库之添加记录

    相关资料:<21天学通Java Web开发> 添加记录1.使用语句对象Statement的executeUpdate()方法可以很方便地实现添加记录.2.只需要在executUpdae() ...

  10. [转]MySQL-5.7 Update语句详解

    原文地址:https://www.cnblogs.com/tongxiaoda/p/7908977.html .语法 (1)单表 UPDATE [LOW_PRIORITY] [IGNORE] tabl ...