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. Android 编程下 Canvas and Drawables

    Canvas and Drawables 安卓提供了一组绘制二维图形的 API(参考官方文档:Canvas and Drawables | Android Developers),这组 API 允许开 ...

  2. Django实现自定义template页面并在admin site的app模块中加入自定义跳转链接

    在文章 Django实现自定义template页面并在admin site的app模块中加入自定义跳转链接(一) 中我们成功的为/feedback/feedback_stats/路径自定义了使用tem ...

  3. MySQL5.7 利用keepalived来实现mysql双主高可用方案的详细过程

    Reference:  http://blog.csdn.net/mchdba/article/details/51377989 服务器准备 Keepalived:192.168.13.15 Keep ...

  4. docker简易命令

    docker应用 安装 sudo yum install docker 启动 docker 进程 $ sudo service docker start Docker 默认开机启动 $ sudo ch ...

  5. 基于jQuery8款超赞的评分插件

    基于jquery8款超赞的评分插件.这是一款基于jquery.barrating插件实现的,该评级小部件可灵活设置CSS样式.具体效果请查看演示.效果图如下: 在线预览   源码下载 实现的代码. h ...

  6. [转]JS组件系列——表格组件神器:bootstrap table

    原文地址:https://www.cnblogs.com/landeanfen/p/4976838.html 前言:之前一直在忙着各种什么效果,殊不知最基础的Bootstrap Table用法都没有涉 ...

  7. sublime Text2下安装php code sniffer插件

    为了跟团队保持开发规范的一致性,需要安装sublime Text2的php code sniffer插件,之前是用的phpfmt插件,发现两个规范还是有点不一样,需要再安装php code sniff ...

  8. HashTable浅析

    本文转载自: http://rock3.info/blog/2013/12/05/hashtable%E6%B5%85%E6%9E%90/ 一.Hash特点 Hash,就是杂凑算法,Hash(str1 ...

  9. InstallShield脚本事件

    脚本事件主要有三大类:Before Move Data(安装数据前).Move Data(安装数据过程中).After Move Data(安装数据后). OnBegin:在初始化后,被调用 OnFi ...

  10. Putty远程SSH免密码方式链接Linxu

    1.首先确保Linxu服务器安装了ssh服务,可以输入ssh命令测试. ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spe ...