Java examples for Swing:JFileChooser
Determining If the Approve or Cancel Button Was Clicked in a JFileChooser Dialog
import javax.swing.JFileChooser; public class Main { public static void main(String[] argv) { JFileChooser chooser = new JFileChooser(); int result = chooser.showOpenDialog(null); // Determine which button was clicked to close the dialog switch (result) { case JFileChooser.APPROVE_OPTION: // Approve (Open or Save) was clicked break;/*from w ww . jav a 2 s . c om*/ 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; } } }