// 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. [Windows Azure] Building worker role A (email scheduler) for the Windows Azure Email Service application - 4 of 5.

    Building worker role A (email scheduler) for the Windows Azure Email Service application - 4 of 5. T ...

  2. Silverlight-MEF-DEMO

    “托管扩展性框架(Managed Extensibility Framework,简称MEF),是微软.NET框架下为提高应用和组件复用程度而推出的,用于使组件能够最大化的重用.使用MEF能够使静态编 ...

  3. 分布式系统唯一ID生成方案汇总【转】

    转自:http://www.cnblogs.com/haoxinyue/p/5208136.html 系统唯一ID是我们在设计一个系统的时候常常会遇见的问题,也常常为这个问题而纠结.生成ID的方法有很 ...

  4. 【Socket】linux黑客之网络嗅探底层原理

      1.mystery引入 1)网络嗅探属于网络攻防类的安全软件,其基于原始套接字技术开发的 2)原始套接字是一种套接字底层技术,它工作在网络层 3)谈到网络安全,刚好本学期学过这门课程,这里myst ...

  5. FFmpeg Basics学习笔记(1)ffmpeg基础

    1 FFmpeg的由来 FFmpeg缩写中,FF指的是Fast Forward,mpeg是 Moving Pictures Experts Group的缩写.官网:ffmpeg.org 编译好的可执行 ...

  6. Lintcode: Kth Largest Element 解题报告

    Kth Largest Element Find K-th largest element in an array. Note You can swap elements in the array E ...

  7. maven pom scope 含义

    maven pom scope 依赖范围控制哪些依赖在哪些classpath 中可用,哪些依赖包含在一个应用中.让我们详细看一下每一种范围: compile (编译范围) compile是默认的范围: ...

  8. JAVA-JSP内置对象之session对象获得session的其他信息

    相关资料:<21天学通Java Web开发> session对象 获得session的其他信息 SessionDemo2.jsp <%@ page language="ja ...

  9. 1. 通俗易懂解释知识图谱(Knowledge Graph)

    1. 通俗易懂解释知识图谱(Knowledge Graph) 2. 知识图谱-命名实体识别(NER)详解 3. 哈工大LTP解析 1. 前言 从一开始的Google搜索,到现在的聊天机器人.大数据风控 ...

  10. java---简单的ATM存取系统,

    新手练手必备~ 密码账户为: 先创建账户类: package cn.Atm; /** * @author 偶my耶 */ import java.io.*; import com.project.pr ...