WebNFS Developer's Guide

Customizing the File Chooser

A file chooser can be customized in a number of ways. (Several of these modifications are shown in Figure 5-7.) Most of the modifications are of the sort that one normally sees with GUI components, such as changing the string in the file chooser's title bar or setting button mnemonics. Certain customizations are more specific to the file chooser, however, and deserve special mention.

Performing a Unique Action

Although the most common use for a file chooser is to open or save files, XFileChooser allows you to select a file for any other action you specify. To this end, a "generic" method for bringing up a file chooser window, showDialog(), is provided in addition to showOpenDialog() and showSaveDialog(). (Since the file chooser itself doesn't affect files, the only difference between a custom dialog and the others is the title on the dialog window and the label on the "accept" button.)

File Filtering

As with the JFileChooser, three types of file filtering are available to the application in bringing up a file chooser:

Setting the FileView

The FileView is the way each file is shown in the file chooser's list of files. By default a small icon and the file's name appear; this can be customized, for example, to show a unique icon next to each filename. An example of this is shown in "Modifying the FileView".

Setting the Accessory

An accessory is a component that is invoked in the file chooser when a file is selected. One example of an accessory might be a panel with controls in it. Another might be a small preview area in the file chooser that displays a thumbnail of a selected graphic file. An example of this kind of customization is given in "Setting the Accessory".