JFileChooser的使用

下面是JFileChooser使用的部分代码:

 

 @Action
    public void selectFileAction() {
        JFileChooser chooser = new JFileChooser();
        FileNameExtensionFilter filter = new FileNameExtensionFilter(
                "JPG & GIF Images", "jpg", "gif");
        chooser.addChoosableFileFilter(new FileNameExtensionFilter("支持的音频文件", "mp3", "wav"));
        chooser.setFileFilter(filter);
        int returnVal = chooser.showDialog(this, "运行");
//        int returnVal = chooser.showSaveDialog(this);
//        int returnVal = chooser.showOpenDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            System.out.println("You chose to open this file: "
                    + chooser.getSelectedFile().getName());
            System.out.println(chooser.getSelectedFile().getAbsolutePath());
        } else if (returnVal == JFileChooser.CANCEL_OPTION) {
            System.out.println("You chose cancel");
        }
    }
 

你可能感兴趣的:(JFileChooser)