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
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
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));
}
});
}
}