![]() |
The Java Developers Almanac 1.4 |
|
e889. Adding a Filter to a File Chooser DialogThis example add a filter for.java files to the file chooser.
JFileChooser fileChooser = new JFileChooser(new File(filename));
fileChooser.addChoosableFileFilter(new MyFilter());
// Open file dialog.
fileChooser.showOpenDialog(frame);
openFile(fileChooser.getSelectedFile());
class MyFilter extends javax.swing.filechooser.FileFilter {
public boolean accept(File file) {
String filename = file.getName();
return filename.endsWith(".java");
}
public String getDescription() {
return "*.java";
}
}
e888. Displaying Only Directories in a File Chooser Dialog e890. Determining If the Approve or Cancel Button Was Clicked in a JFileChooser Dialog e891. Getting and Setting the Current Directory of a JFileChooser Dialog e892. Getting and Setting the Selected File of a JFileChooser Dialog e893. Getting the File-Type Name of a File e894. Copying the Filename Path from a JFileChooser Dialog to the Clipboard
© 2002 Addison-Wesley. |