e777. 获得JList组件的所有项
// 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组件的所有项的更多相关文章
- e776. 设置JList组件项的提示语
// Create a list, overriding the getToolTipText() method String[] items = {"A", "B&qu ...
- e775. 设置JList组件项的维数
By default, the width of the list is determined by the longest item and the height is determined by ...
- 【技巧】EasyUI分页组件pagination显示项控制
我们使用easyui分页时,分页组件显示项有很多,默认如下是这样的: 有时候我们并不想显示这么多控制项,我们可以通过属性来控制:如下来自EasyUI官网: 如下写法,在datagrid中使用,如下控制 ...
- e774. 创建JList组件
By default, a list allows more than one item to be selected. Also, the selected items need not be co ...
- Swing学习篇 API之JButton组件
按钮(Jbutton) Swing中的按钮是Jbutton,它是javax.swing.AbstracButton类的子类,swing中的按钮可以显示图像,并且可以将按钮设置为窗口的默认图标,而且还可 ...
- java中经常使用的Swing组件总结
1.按钮(Jbutton) Swing中的按钮是Jbutton,它是javax.swing.AbstracButton类的子类,swing中的按钮可以显示图像,并且可以将按钮设置为窗口的默认图标,而且 ...
- Swing学习篇 API [一]Swing常用组件
1.按钮(Jbutton) Swing中的按钮是Jbutton,它是javax.swing.AbstracButton类的子类,swing中的按钮可以显示图像,并且可以将按钮设置为窗口的默认图标,而且 ...
- java中常用的swing组件 (2013-10-27-163 写的日志迁移
五种布局: 流式布局(FlowLayout)边界布局(borderLayout)网格布局(GridLayout) 盒子布局(BoxLaYout) 空布局(null) 常用的几种 卡片布局(C ...
- java列表组件鼠标双击事件的实现
Swing中提供两种列表组件,分别是列表框(JList)和组合框(JComboBox). 一.JList组件 构造方法: public JList():构造一个空的.具有只读模型的JList.publ ...
随机推荐
- [Windows Azure] How to Create and Configure SQL Database
How to Create and Configure SQL Database In this topic, you'll step through logical server creation ...
- jqgrid传入的json数据,赋值了但是没有在表格上显示
1. datatype: "local",属性加入这个 2. dataValue就是json对象 for (var i = 0; i <= dataValue.length ...
- 每日英语:Google Scraps Plan to Build Hong Kong Data Center
Internet giant Google Inc. has scrapped a plan to build its own data center in Hong Kong and will in ...
- Linux screen用法简介
[admin@VM_0_2_centos ~]$ screen -bash: screen: 未找到命令 [admin@VM_0_2_centos ~]$ sudo su [sudo] passwor ...
- squid搭建http/https代理服务器
前言:笔者使用的长城宽带,访问国外网站,比如mysql,nginx等站点的速度.......,你懂得,于是想到使用腾讯云主机搭建squid代理服务器,这里搭建的是一般代理服务器,squid代理服务器分 ...
- git stash 暂存恢复和文件误删恢复
git commit提交文件,服务器返回本地文件有修改. 1.git stash :暂存本地代码 2.git pull origin develop : 获取远程分支代码 3.git stash po ...
- [转载]CMMI之功能点估算法:EI、EQ和EO
EI.EO.EQ EI是处理来自于应用程序边界外部的一组数据的输入,它的主要目的是维护一个或多个ILF,以及/或者更改系统的行为. EO是输送数据到应用程序边界外部的过程.它的主要目的是通过逻辑处理过 ...
- iOS全局变量的声明和使用
在一个项目中,我们可能需要定义几个全局变量,在我们程序的任何位置都可以进行访问,提高我们的开发效率.在iOS中我们如何来实现呢?我们主要使用的是AppDelegate类来实现.如下: (1)AppDe ...
- How to Use updateConstraints(什么时候该使用updateConstraints)
How to Use updateConstraintshtml, body {overflow-x: initial !important;}html { font-size: 14px; } bo ...
- PHP程序员如何理解IoC/DI(转)
php - Dependency Injection依赖注入 和 自动加载 各自的优缺点 ioc/di和自动加载时两回事. ioc/di 让代码由创建对象改为注入对象,是一种编程思想,而自动加载,只是 ...