tags:

views:

126

answers:

1

Can anyone guide me or give an example of how to insert components, or files of components, or their folder into JList. This has being an issue pending, please assist.

+1  A: 
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);
  }
});
Adamski