Reputation: 1596
If i want to add an ArrayList
to a JList
, it is not shown in the list, but the array contains the items. How could i fix this?
public void updateLeftList(){
// Enter the search text
interFace.Search.setText(this.search);
// Get the left list
JList leftList = interFace.LeftList;
leftList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
// Define the arraylists
allPdf = new ArrayList();
curPdf = new ArrayList();
addPdf = new ArrayList();
// Get Files from manuals folder
File files = new File(configFile.getProperty("dir") + "/" + this.taal);
File[] listFiles = files.listFiles();
for(int i = 0; i < listFiles.length; i++){
if(listFiles[i].getName().endsWith(".pdf") && listFiles[i].isFile()){
allPdf.add(listFiles[i].getName().toString());
}
}
leftList.setListData(allPdf.toArray());
}
Upvotes: 1
Views: 101
Reputation: 1326
for(Object item : arrayList.toArray()){
((DefaultListModel) list1.getModel()).addElement(item);
}
Upvotes: 0
Reputation: 1497
use ListModel to add the data:
1. create new instance of DefaultListModel
2. add your file names to the list model
3. set it as your JList
list model
Upvotes: 1