Speed Swing Setup

Speed Swing Setup

In Swing 0.7, and probably later versions as well, the DefaultListModel class notifies its ListDataListeners every time a new element is added to the list model. For very large lists this can result in extremely slow JList updates. To work around the issue, set the JList’s model to null before updating the list, then reset the JList’s model when you’re through. This way no expensive event signaling is performed, speeding up your list update. Don’t forget to repaint and revalidate the JList, because a JList does not update its appearance after setModel() is called.

A short demonstration follows. Note that we actually clear the list and refill it with new data, which requires making sure the selection gets cleared and that the top of the list is visible.

 list.setModel(null);listModel.removeAllElements();for(int i=0; i 


Share the Post: