If you want to make a copy of the content, you can use DefaultListModel.toArrayto get the data and create your favorite implementation Listwith it. Alternatively, you can run the loop ListModel.getElementAt ListModel.getSizeonce.
If you need a live connection between collections, not a copy, use AbstractList:
public static List<Object> asList(final DefaultListModel model) {
return new AbstractList<Object>() {
@Override public Object get(int index) {
return model.getElementAt(index);
}
...
};
}
You might want to put it Class.castthere, but there is a problem with the fact that Swing types are not common.
source
share