// Create a list
String[] items = {"A", "B", "C", "D"};
JList list = new JList(items); // Get number of items in the list
int size = list.getModel().getSize(); // 4 // Get all item objects
for (int i=0; i<size; i++) {
Object item = list.getModel().getElementAt(i);
}

These methods are used to find an item:

    // The prefix is case-insensitive
String prefix = "b"; // Search forward, starting from index 0, looking for an item that starts with "b"
int start = 0;
javax.swing.text.Position.Bias direction = javax.swing.text.Position.Bias.Forward;
int itemIx = list.getNextMatch(prefix, start, direction); // Search backward, starting from the last item, looking for an item that starts with "b"
start = list.getModel().getSize()-1;
direction = javax.swing.text.Position.Bias.Backward;
itemIx = list.getNextMatch(prefix, start, direction);

These methods can be used to find the range of visible items:

    // Get number of visible items
int visibleSize = list.getVisibleRowCount(); // Get index of first visible item
itemIx = list.getFirstVisibleIndex();
if (itemIx < 0) {
// List is either not visible or there are no items
} // Get index of last visible item
itemIx = list.getLastVisibleIndex();
if (itemIx < 0) {
// List is either not visible or there are no items
}
Related Examples

e777. 获得JList组件的所有项的更多相关文章

  1. e776. 设置JList组件项的提示语

    // Create a list, overriding the getToolTipText() method String[] items = {"A", "B&qu ...

  2. e775. 设置JList组件项的维数

    By default, the width of the list is determined by the longest item and the height is determined by ...

  3. 【技巧】EasyUI分页组件pagination显示项控制

    我们使用easyui分页时,分页组件显示项有很多,默认如下是这样的: 有时候我们并不想显示这么多控制项,我们可以通过属性来控制:如下来自EasyUI官网: 如下写法,在datagrid中使用,如下控制 ...

  4. e774. 创建JList组件

    By default, a list allows more than one item to be selected. Also, the selected items need not be co ...

  5. Swing学习篇 API之JButton组件

    按钮(Jbutton) Swing中的按钮是Jbutton,它是javax.swing.AbstracButton类的子类,swing中的按钮可以显示图像,并且可以将按钮设置为窗口的默认图标,而且还可 ...

  6. java中经常使用的Swing组件总结

    1.按钮(Jbutton) Swing中的按钮是Jbutton,它是javax.swing.AbstracButton类的子类,swing中的按钮可以显示图像,并且可以将按钮设置为窗口的默认图标,而且 ...

  7. Swing学习篇 API [一]Swing常用组件

    1.按钮(Jbutton) Swing中的按钮是Jbutton,它是javax.swing.AbstracButton类的子类,swing中的按钮可以显示图像,并且可以将按钮设置为窗口的默认图标,而且 ...

  8. java中常用的swing组件 (2013-10-27-163 写的日志迁移

    五种布局:   流式布局(FlowLayout)边界布局(borderLayout)网格布局(GridLayout)  盒子布局(BoxLaYout)  空布局(null)  常用的几种 卡片布局(C ...

  9. java列表组件鼠标双击事件的实现

    Swing中提供两种列表组件,分别是列表框(JList)和组合框(JComboBox). 一.JList组件 构造方法: public JList():构造一个空的.具有只读模型的JList.publ ...

随机推荐

  1. 歌曲播放页面的数据vuex管理

    1.state.js import {playMode} from '@/common/js/config' const state = { singer:{}, playing:false, ful ...

  2. hive添加UDF

    hive添加UDF 步骤如下: 函数分为永久和临时函数,后者会话退出则消失,前者不会 查看已有函数(创建好后也可以通过这个来查看是否成功) show functions; 写UDF的java文件,如: ...

  3. Android中隐藏标题栏和状态栏

    http://www.cnblogs.com/zhuguangwei/archive/2011/01/18/1938276.html 一.隐藏标题栏 //隐藏标题栏 this.requestWindo ...

  4. eclipse Maven 使用记录 ------ 建立app项目

    maven 项目构建工具 , 如今已逐渐取代ant的笨拙配置方式 ,使项目管理更加简单,规范,结构更加清晰,这里记录跟eclipse集成的一些步骤  1.从apache maven项目下下载maven ...

  5. Silverlight跨域访问wcf

    添加文件名为“clientaccesspolicy.xml”的文件 内容: <?xml version="1.0" encoding="utf-8"?&g ...

  6. Node.js学习笔记(6)--异步变同步

    说明(2017-5-3 14:59:03): 1. 异步变同步: var fs = require("fs"); var documents = []; fs.readdir(&q ...

  7. iOS手机号,身份证,车牌号正则表达式

    1.手机号判断,根据维基百科2016年6月修订的段号判断 是否是手机号 /** 手机号码 13[0-9],14[5|7|9],15[0-3],15[5-9],17[0|1|3|5|6|8],18[0- ...

  8. XXE漏洞初窥

    前言: XXE Injection即XML External Entity Injection也就是XML外部实体注入攻击.漏洞是在对非安全的外部实体数据进⾏行处理时引发的安全问题. XML相关名词科 ...

  9. Linux下nginx 的常用命令

    启动 启动代码格式:nginx安装目录地址 -c nginx配置文件地址 例如: [root@LinuxServer sbin]# /usr/local/nginx/sbin/nginx -c /us ...

  10. C语言 · 校门外的树

    算法提高 校门外的树   时间限制:1.0s   内存限制:256.0MB      问题描述 某校大门外长度为L的马路上有一排树,每两棵相邻的树之间的间隔都是1米.我们可以把马路看成一个数轴,马路的 ...