[英]inserting folder containing components into JList
Can anyone guide me or give an example of how to insert components, or files of components, or their folder into JList
. 任何人都可以指导我或提供一个示例,说明如何将组件,组件文件或它们的文件夹插入
JList
。 This has being an issue pending, please assist. 这是一个待解决的问题,请协助。
List<File> files = ... // Obtain files from somewhere ...
// Pass files as an array to JList. Could alternatively implement custom ListModel.
Object[] arr = files.toArray();
JList jl = new JList(arr);
// Define renderer to display full file names:
jl.setCellRenderer(new DefaultListCellRenderer() {
public void getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
File file = (File)value;
return super.getListCellRendererComponent(list, file.getPath(), index, isSelected, cellHashFocus);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.