The following methods return the indices of the selected items:

  1. // To create a list, see e774 创建JList组件
  2.  
  3. // Get the index of all the selected items
  4. int[] selectedIx = list.getSelectedIndices();
  5.  
  6. // Get all the selected items using the indices
  7. for (int i=0; i<selectedIx.length; i++) {
  8. Object sel = list.getModel().getElementAt(selectedIx[i]);
  9. }
  10.  
  11. // Get the index of the first selected item
  12. int firstSelIx = list.getSelectedIndex();
  13.  
  14. // Get the index of the last selected item
  15. int lastSelIx = list.getMaxSelectionIndex();
  16.  
  17. // Determine if the third item is selected
  18. int index = 2;
  19. boolean isSel = list.isSelectedIndex(index);
  20.  
  21. // Determine if there are any selected items
  22. boolean anySelected = !list.isSelectionEmpty();

The following methods return the selected item objects:

  1. // Get the first selected item
  2. Object firstSel = list.getSelectedValue();
  3.  
  4. // Get all selected items without using indices
  5. 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. windows 定时任务:schtasks,定时关闭网易云音乐

    大部分属于转载和粘贴. 使用命令:schtasks windows 定时任务   使用样例: 每天定时关闭网易云音乐: 每天22:20关闭网易云音乐: schtasks /create /tn &qu ...

  2. 关于构造函数和this调用的思考

    文中一系列思考和内容引发自以下问题:我需要在一个类的构造函数中调用另一个对象的构造函数,并使用this初始化其中的一个引用成员. 主要遇到的问题: 1. 构造函数的初始化列表中能访问this吗? 很明 ...

  3. Mac系统安装Lua

    1.下载最新版的lua-5.2.3 请点击,然后解压 2. 运行“终端”进入到该文件夹下,主要是cd [文件夹名] 3.在“终端”输入    make macosx   (回车) 4.在“终端”输入  ...

  4. 01-老马jQuery教程-jQuery入口函数及选择器

    前言 这套jQuery教程是老马专门为寒门子弟而录制,希望大家看到后能转发给更多的寒门子弟.视频都是免费,请参考课程地址:https://chuanke.baidu.com/s5508922.html ...

  5. CTF之文件包含的猥琐思路

    From: i春秋 百度杯”CTF 一: <?php include "flag.php"; //包含flag.php这个文件 $a = @$_REQUEST['hello' ...

  6. 图解在VC里使用graphics.h画图(相似TC)

    1 www.easyx.cn 下载 EasyX 库 我下的2014;解压后例如以下图: 2 依据自己的VC 版本号进行安装 3 在控制台画一个圆 #include <graphics.h> ...

  7. sparkonhbase

    import org.apache.hadoop.hbase.HBaseConfiguration import org.apache.hadoop.hbase.client.Result impor ...

  8. StreamingContext.getOrCreate

    /** */ object AppRealTime { def main(args: Array[String]): Unit = { ) { println("please input a ...

  9. PHPUnit 手册(转)

    PHPUnit 手册 PHPUnit 手册 Sebastian Bergmann 版权 © 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, ...

  10. RabbitMQ文档翻译——Work queues

    原文链接:https://www.rabbitmq.com/tutorials/tutorial-two-java.html Work Queues (using the Java Client) I ...