JFileChooser有一些文件名的错误?

时间:2013-09-13 23:15:51

标签: java regex swing jfilechooser filefilter

我正在使用Ubuntu,我尝试在我的java应用程序中使用JFileChooser,但似乎它有文件名的问题可以用这个正则表达式来描述:

.*\[.*\].*

这意味着包含“[”和“]”的文件名。 Dialog只是拒绝选择这样的文件进行保存。我是唯一一个有这个问题的人吗?可能是什么问题?

我使用了oracle jre和open-jdk jre。

修改

private void btnSelectSrcMouseClicked(java.awt.event.MouseEvent evt) {                                          
       int result = filechooser.showDialog(this,"Select");

       if(result == JFileChooser.APPROVE_OPTION){
           sourceFile = filechooser.getSelectedFile();
           this.txtFilePath.setText(sourceFile.getAbsolutePath());
       }
    }                                         

private void btnSelectDestMouseClicked(java.awt.event.MouseEvent evt) {                                           
        int result = filechooser.showDialog(this,"Select");

       if(result == JFileChooser.APPROVE_OPTION){
           destinationFile = filechooser.getSelectedFile();
           this.txtDestPath.setText(destinationFile.getAbsolutePath());
       }
    }

这是代码。使用JFileChooser的一个实例有两个目的,首先是当用户单击一个按钮弹出对话框并且用户选择文件时。然后在单击另一个按钮后弹出相同的对话框,用户选择当时可能不存在的目标文件。如果文件名如上所述,那么在点击“选择”按钮(我弄错了,我没有打开JFileChooser作为保存对话框)后,对话框底部的文件类型与文件名文本字段的值相同。点击“选择”几次后,它什么也没做。

0 个答案:

没有答案