Java Reference
In-Depth Information
public boolean isHiddenFile(File file);
public boolean isParent(File folder, File file);
public boolean isRoot(File file);
public Boolean isTraversable(File file);
}
Note Notice that the isTraversable() method returns a Boolean , not a boolean . (I haven't a clue
why the difference—perhaps somewhere an object is needed, and the primitive boolean wasn't sufficient.)
FileView Class
The final part of the JFileChooser class to examine is the FileView area where all the file names
are listed. Each of the custom look and feel types has its own FileView area class. In addition,
some of the predefined look and feel types, such as Motif, aren't changeable. Nevertheless, at
least in the Metal and Windows file choosers, you can customize the icons for different file
types or change the display name for a file.
The five methods of the FileView class allow you to change the name, icon, or description (two
forms) of each File in the view. In addition, the FileView actually controls whether a directory
is traversable, allowing you to program in a weak level of access control. Nontraversable directories
have a different default icon, because those directories cannot be browsed for file selection.
Here's the definition of the abstract FileView class:
public abstract class FileView {
public FileView();
public String getDescription(File file);
public Icon getIcon(File file);
public String getName(File file);
public String getTypeDescription(File file);
public Boolean isTraversable(File file);
}
Note Like FileSystemView , the isTraversable() method returns a Boolean value, not a boolean one.
Customizing the FileView requires creating a subclass and overriding the appropriate
methods. By default, all the methods return null , indicating that you don't want to define
custom behavior for a specific method.
Once you've defined the file view, simply change the fileView property of your JFileChooser :
fileChooser.setFileView(new JavaFileView());
Figure 9-29 shows the changed appearance of a Metal JFileChooser after installing a
custom FileView .
 
Search WWH ::




Custom Search