I have a JList and I use a DefaultListModel to store the list entries. I have a button on that panel. When the button is clicked, I add new entry to DefaultListModel .
button actionPerformed:
My problem is, after I did the operation on my DefaultListModel, the content of JList doesn't change, I'm wondering that do I need to call a sort of refresh method on JList after I make changes on the ListModel?
public void actionPerformed(ActionEvent e) {
ModifyXMLFile.create(FileList.listModel);
FileList.fileList1.revalidate();
}
JList Class:
public class FileList {
public static DefaultListModel listModel;
public static WebList fileList1 = null;
public static Component getGui(File[] all) {
listModel = new DefaultListModel();
for(File file:all){
listModel.addElement(file);
}
final WebList fileList = new WebList(listModel);
fileList1=fileList;
fileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
fileList.setCellRenderer(new FileRenderer(!vertical));
fileList.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
});
}