// 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

最新文章

  1. php 路径
  2. Unity3D 导航网格自动寻路(Navigation Mesh)
  3. js&#39;中的apply和call和bind的用法
  4. zookeeper能做什么?
  5. 好用的Magento一步支付插件One Step Checkout免费版
  6. [Effective JavaScript笔记]第3条:当心隐式的强制转换
  7. C++注意事项锦集
  8. mysql 前缀索引
  9. BZOJ3942 [Usaco2015 Feb]Censoring
  10. Windows Server 2012 R2 设置
  11. 装饰器模式(Decorator)
  12. (转)IIS7 下部署Asp.net应用
  13. OLAP与数据仓库------《Designing Data-Intensive Applications》读书笔记4
  14. 【javascript】onblur调用函数失效问题记录
  15. 在PHP中使用AES加密算法加密数据
  16. hdu2973-YAPTCHA-(欧拉筛+威尔逊定理+前缀和)
  17. VS无法导航到插入点F12失败
  18. EasyUI常用控件禁用方法
  19. linux page table entry struct
  20. C语言头文件#include&lt;stdlib.h&gt;的作用

热门文章

  1. Oracle根据表生成系统流水号
  2. django rest_framework入门二-序列化
  3. ZooKeeper示例 分布式锁
  4. 【Linux技术】磁盘的物理组织,深入理解文件系统
  5. How to disable SSL certificate checking with Spring RestTemplate?(使用resttemplate访问https时禁用证书检查)
  6. 【LDA】线性判别式分析
  7. ViewGroup
  8. Python如何下载文件
  9. 主流Java数据库连接池分析(C3P0,DBCP,TomcatPool,BoneCP,Druid)
  10. JAVA-数据库之Statement对象