Displaying large amount of data with JList?

限于喜欢 提交于 2019-12-02 04:32:58
mKorbel

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

StKiller

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. The following example shows the usage of AbstractTableModel.

I have a JList, wich must display more than 3000 items.

Huh. You make that sound like a big number. Here is a list holding (and displaying just fine), more than 30 thousand items.

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));
            }
        });
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!