任何人都可以指导我或举例说明如何将组件或组件文件或其文件夹插入JList
。这是一个悬而未决的问题,请协助。
答案 0 :(得分:1)
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);
}
});