Displaying large amount of data with JList?

前端 未结 3 595
再見小時候
再見小時候 2021-01-24 08:45

I have a JList, wich must display more than 3000 items. I wish to have \"visible\" around 100 items in the list, and when you scroll and getting close to the end (or begining) o

相关标签:
3条回答
  • 2021-01-24 09:24

    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

    0 讨论(0)
  • 2021-01-24 09:36

    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.

    0 讨论(0)
  • 2021-01-24 09:36

    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.

    Big List

    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));
                }
            });
        }
    }
    
    0 讨论(0)
提交回复
热议问题