简体   繁体   中英

Why does showOpenDialog() open more file choosers?

I am trying to create a 'Save to' file chooser. However when i execute the code and hit 'Open' a new filechooser window is opened. The code:

int val = jFileChooser1.showOpenDialog(null);

private void jFileChooser1ActionPerformed(java.awt.event.ActionEvent evt) {

    System.out.println(evt.getActionCommand());

    int val = jFileChooser1.showOpenDialog(null);

    if(val == jFileChooser1.APPROVE_OPTION){
        File filePath = jFileChooser1.getSelectedFile();
         directoryPath = filePath.toString();
         System.out.println("Directory Path: " + directoryPath);
    }else{
        System.exit(0);
    }

}

尝试使用showSaveDialog方法。

int val = jFileChooser1.showOpenDialog(parent);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM