// 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. Burpsuite如何抓取使用了SSL或TLS传输的 IOS App流量

    之前一篇文章介绍了Burpsuite如何抓取使用了SSL或TLS传输的Android App流量,那么IOS中APP如何抓取HTTPS流量呢, 套路基本上与android相同,唯一不同的是将证书导入i ...

  2. python(46):对字典进行排序,多键值排序

    注:改于2017-12-07,python3 下 Removed dict.iteritems(), dict.iterkeys(), and dict.itervalues(). Instead: ...

  3. Lua函数[转]

    在大多数Lua语法分析中可以获得这些标准Lua函数. 无可争辩, 我们可以查阅Lua网站, 但是一些少了的函数被Blizzard进行了调整. 下面列出了所有Lua函数. WoW API中的Lua注意在 ...

  4. 判断URL文件是不是在于在。

    判断URL文件是不是在于在. private static bool UrlIsExist(string url) { System.Uri u = null; try { u = new Uri(u ...

  5. JS实现多行文本最后是省略号紧随其后还有个超链接在同一行的需求

    1.布局及样式如下图: 2.js获得上图的div对象,然后判断div对象的高度,如果大于一行的高度了表示内容有两行了,再获得span标签里面的内容并用正则将后六个字符替换成“......”这里的实现代 ...

  6. C#学习笔记(25)——用刻盘器批量从U盘删除添加文件

    说明(2017-11-17 14:46:05): 1. 因为经常要从U盘里面删除版本,然后添加版本,每次都要几个人手动复制粘贴,费时费力,就花了一下午时间写了个程序,自动删除和添加版本. 2. Dri ...

  7. C#学习笔记(21)——C#获取文件夹下的所有文件的文件名

    说明(2017-7-30 23:11:59): 1. 文件处理老是忘,学的不扎实. 2. 路径用Directory,文件名用file. 3. 我也推荐用第二种方法,可以拿到文件的所有信息,比如扩展名什 ...

  8. oracle的db link

    cd $ORACLE_HOME/network/admin vi tnsnames.ora 添加 CCPBS_19 =  (DESCRIPTION =    (ADDRESS_LIST =      ...

  9. mysql hive sql 进阶

    场景: 说明.1.上面的数据是经过规整的数据,step是连续的,这个可以通过row_number实现.连续是必要的一个条件因为在计算第二个查询条件时依赖这个顺序,如果step不是数字字段可以截取然后转 ...

  10. Mongo分区后分片下count记录不准确

    问题描述 问题如图,后来上网查了一下,发现了这是正常现象: 官方文档解释了这种现象的原因以及解决方法: 不准确的原因: 操作的是分片的集合(前提): shard分片正在做块迁移,导致有重复数据出现 存 ...