Reputation: 21
I have JList
code that I want to add to a scroll button on the side since the list is longer than the text box window.
that's the code:
final JList list = new JList();
list.setBounds(36, 23, 366, 241);
contentPane.add(list);
File folder = new File(FILETOSTART);
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
System.out.println("File " + listOfFiles[i].getName());
list.setListData(listOfFiles);
} else if (listOfFiles[i].isDirectory()) {
System.out.println("Directory " + listOfFiles[i].getName());
}
}
}
in.close();
}
catch (Exception exception) {
exception.printStackTrace();
How can I add this scroll side button?
Upvotes: 0
Views: 181
Reputation: 168825
If by 'button' you mean 'scroll bar' then it can be1 as simple as:
contentPane.add(new JScrollPane(list));
Instead of:
contentPane.add(list);
Upvotes: 2