简体   繁体   English

使用JList显示大量数据?

[英]Displaying large amount of data with JList?

I have a JList, wich must display more than 3000 items. 我有一个JList,必须显示3000多个项目。 I wish to have "visible" around 100 items in the list, and when you scroll and getting close to the end (or begining) of the "visible" items the next portion (around 50) must be loaded in the list. 我希望列表中约有100个项目处于“可见”状态,并且当您滚动并接近“可见”项目的末尾(或开头)时,必须在列表中加载下一部分(约50个)。 Is there any simple way of doing this? 有没有简单的方法可以做到这一点?

The list is rendering only the visible part. 该列表仅呈现可见部分。 So there is no overhead from this point of view. 因此,从这个角度来看,没有任何开销。 If you want lazy loading - use custom models. 如果要延迟加载-使用自定义模型。

From this page : 从此页面
You can write your own class that extends AbstractListModel or AbstractTableModel so that you can provide the needed data when necessary. 您可以编写自己的类来扩展AbstractListModel或AbstractTableModel,以便在必要时可以提供所需的数据。 The following example shows the usage of AbstractTableModel. 下面的示例演示AbstractTableModel的用法。

no there are no simple way for that, you have to implements Pagination(s) 不,没有简单的方法,您必须实现分页

  • easiest job when is managed by Databases engine, most of then support paginations directly 由数据库引擎管理时最简单的工作,然后大多数直接支持分页

  • in the Model, but I never seen workaround for XxxListModel, use JTable with one Colum instead, there are some good workaround for Pagination for JTable 在模型中,但我从未见过XxxListModel的解决方法,而是将JTable与一个Colum一起使用,对于JTable的分页有一些不错的解决方法

I have a JList, wich must display more than 3000 items. 我有一个JList,必须显示3000多个项目。

Huh. You make that sound like a big number. 您让听起来像个大数目。 Here is a list holding (and displaying just fine), more than 30 thousand items. 这是一个列表列表(显示得很好),超过3 万个项目。

大清单

import javax.swing.*;

class BigList {

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                int bigNumber = 30001;
                String[] bigData = new String[bigNumber];
                for (int ii=0; ii<bigNumber; ii++) {
                    bigData[ii] = "String " + (ii+1);
                }
                JList list = new JList(bigData);
                list.setVisibleRowCount(5);

                JOptionPane.showMessageDialog(null, new JScrollPane(list));
            }
        });
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM