Java Reference
In-Depth Information
Figure 9-29. Changing the FileView
The JavaFileView class in Listing 9-17 provides a FileView implementation that customizes
the appearance of files related to Java development—specifically, .java , .class , .jar , and
.html or .htm files. (This is certainly not meant to be a comprehensive list of Java file types.) For
each of these file types, a special icon instead of the default icon is displayed next to the name.
In addition, for Java source files, the length of the file is displayed. (Imagine if every file attribute
were being displayed!) Unfortunately, you can't modify the font or color from a FileView .
Listing 9-17. Custom FileView for Some Java-Related File Types
import java.io.File;
import java.awt.*;
import javax.swing.*;
import javax.swing.filechooser.*;
public class JavaFileView extends FileView {
Icon javaIcon = new DiamondIcon(Color.BLUE);
Icon classIcon = new DiamondIcon(Color.GREEN);
Icon htmlIcon = new DiamondIcon(Color.RED);
Icon jarIcon = new DiamondIcon(Color.PINK);
public String getName(File file) {
String filename = file.getName();
if (filename.endsWith(".java")) {
String name = filename + " : " + file.length();
return name;
}
return null;
}
Search WWH ::




Custom Search