Tai
Tai

Reputation: 63

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);
    }

}

Upvotes: 3

Views: 249

Answers (2)

Andrew Thompson
Andrew Thompson

Reputation: 168845

int val = jFileChooser1.showOpenDialog(parent);

Upvotes: 2

Mikita Belahlazau
Mikita Belahlazau

Reputation: 15434

Try showSaveDialog method.

Upvotes: 3

Related Questions