Java problem: needs a sorted JList to represent a database table
I found a sample for a sorted JList, but my application is equipped with an embedded H2 base, so I'm wondering if there is no better way to implement this with this in mind. Especially considering that the table in question can get extremely large and duplicating all of that data in the JList model seems to win in having a database to manage it.
Is there a good way to do this? Or am I forced to iron out some awkward hack to let the JList "loop through" dynamically requested chunks of data, or something?
a source to share
Yours JList
ListModel
is responsible for publishing the backup data as an ordered list. ListModel
the methods will be called JList
from the user interface thread (AWT), so its performance should be pretty good. This is why most implementations have support data ListModel
in memory. I suppose you could implement ListModel
with your database as backup data. You will most likely go ahead AbstractListModel
to get the listener registration and do getElementAt(int)
and getSize()
. getElementAt
will be responsible for getting the object for a specific index. Keep in mind that JList
many times callgetElementAt
for different indexes, so you might find results caching. Depending on how much data you are caching, you can simply fetch the entire dataset from the database.
a source to share