WebNFS Developer's Guide

Modifying the FileView

The FileView is the way a file in a list is presented. By default, a file chooser shows each file with a small icon showing whether the file is a directory of a flat file. An example of a modified FileView is seen in Figure 5-8; compare the icon shown next to the file shakes2.gif to the icon that appears in next to it in Figure 5-1.

Setting the FileView works in the same way as filtering files does. Here's how it's done in XFileChooserDemo:

  1. Create a custom subclass of the class FileViewapi, overriding any of its abstract methods you need. For this sample program, one has been created called ExampleFileView (see "ExampleFileView"), which looks at a file's extension (for example,.jpg) and returns the file's name and, if the extension indicates that the file is a graphic file, an icon representing that type of file.

  2. Create a FileView object.


    fileView = new ExampleFileView();

  3. Add a checkbox for changing the FileView, and add a listener to it.


    useFileViewButton = new JCheckbox("Use FileView");
    useFileViewButton.addActionListener(optionListener);

  4. In optionListener(), call setFileView() when the Use FileView checkbox gets selected.


    if (c == useFileViewButton) {
         if (useFileViewButton.isSelected() {
              chooser.setFileView(fileView);
         else
                    chooser.setFileView(null);
    

Now when a file chooser is brought up ExampleFileView will be used to display the files in the file list.