Determining If the Approve or Cancel Button Was Clicked in a JFileChooser Dialog

JFileChooser chooser = new JFileChooser(); // Show the dialog; wait until dialog is closed int result = chooser.showOpenDialog(frame); // Determine which button was clicked to close the dialog switch (result) { case JFileChooser.APPROVE_OPTION: // Approve (Open or Save) was clicked break; case JFileChooser.CANCEL_OPTION: // Cancel or the close-dialog icon was clicked break; case JFileChooser.ERROR_OPTION: // The selection process did not complete successfully break; }

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.