e777. 获得JList组件的所有项
2024-09-17 21:18:45
// 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 |
最新文章
- php 路径
- Unity3D 导航网格自动寻路(Navigation Mesh)
- js&#39;中的apply和call和bind的用法
- zookeeper能做什么?
- 好用的Magento一步支付插件One Step Checkout免费版
- [Effective JavaScript笔记]第3条:当心隐式的强制转换
- C++注意事项锦集
- mysql 前缀索引
- BZOJ3942 [Usaco2015 Feb]Censoring
- Windows Server 2012 R2 设置
- 装饰器模式(Decorator)
- (转)IIS7 下部署Asp.net应用
- OLAP与数据仓库------《Designing Data-Intensive Applications》读书笔记4
- 【javascript】onblur调用函数失效问题记录
- 在PHP中使用AES加密算法加密数据
- hdu2973-YAPTCHA-(欧拉筛+威尔逊定理+前缀和)
- VS无法导航到插入点F12失败
- EasyUI常用控件禁用方法
- linux page table entry struct
- C语言头文件#include<;stdlib.h>;的作用
热门文章
- Oracle根据表生成系统流水号
- django rest_framework入门二-序列化
- ZooKeeper示例 分布式锁
- 【Linux技术】磁盘的物理组织,深入理解文件系统
- How to disable SSL certificate checking with Spring RestTemplate?(使用resttemplate访问https时禁用证书检查)
- 【LDA】线性判别式分析
- ViewGroup
- Python如何下载文件
- 主流Java数据库连接池分析(C3P0,DBCP,TomcatPool,BoneCP,Druid)
- JAVA-数据库之Statement对象