Example usage for javax.swing JFileChooser CANCEL_OPTION

List of usage examples for javax.swing JFileChooser CANCEL_OPTION

Introduction

In this page you can find the example usage for javax.swing JFileChooser CANCEL_OPTION.

Prototype

int CANCEL_OPTION

To view the source code for javax.swing JFileChooser CANCEL_OPTION.

Click Source Link

Document

Return value if cancel is chosen.

Usage

From source file:Main.java

public static void main(String[] argv) {
    JFileChooser chooser = new JFileChooser();
    int result = chooser.showOpenDialog(null);
    switch (result) {
    case JFileChooser.APPROVE_OPTION:
        System.out.println("Approve (Open or Save) was clicked");
        break;/*from  w w w. ja va 2 s .  c om*/
    case JFileChooser.CANCEL_OPTION:
        System.out.println("Cancel or the close-dialog icon was clicked");
        break;
    case JFileChooser.ERROR_OPTION:
        System.out.println("Error");
        break;
    }
}

From source file:Main.java

public static void main(String[] args) {
    String path = System.getProperty("user.dir", ".");

    File dir = new File(path);

    JFileChooser jfc = new JFileChooser(dir);
    int result = jfc.showOpenDialog(null);

    switch (result) {
    case JFileChooser.CANCEL_OPTION:
        System.out.println("User cancelled OPEN dialog.");
        break;/*from  w ww . j av a 2 s.  c o  m*/
    case JFileChooser.APPROVE_OPTION:
        System.out.println("User chose file: " + jfc.getSelectedFile());
        break;
    case JFileChooser.ERROR_OPTION:
        System.out.println("User encountered an error");
        break;
    default:
        System.out.println("Confused");
        break;
    }

    System.exit(0);
}

From source file:Main.java

public static void main(String[] a) {
    JFileChooser fileChooser = new JFileChooser(".");
    int status = fileChooser.showOpenDialog(null);

    if (status == JFileChooser.APPROVE_OPTION) {
        File[] selectedFiles = fileChooser.getSelectedFiles();
    } else if (status == JFileChooser.CANCEL_OPTION) {
        System.out.println("canceled");
    }//from  ww w. j  a v  a  2s .c  om
}

From source file:JFileChooserSelectionOption.java

public static void main(String[] a) {
    JFileChooser fileChooser = new JFileChooser(".");
    int status = fileChooser.showOpenDialog(null);

    if (status == JFileChooser.APPROVE_OPTION) {
        File selectedFile = fileChooser.getSelectedFile();
        System.out.println(selectedFile.getParent());
        System.out.println(selectedFile.getName());
    } else if (status == JFileChooser.CANCEL_OPTION) {
        System.out.println("canceled");
    }/*from  www.  j av a  2s.c  o  m*/
}

From source file:MainClass.java

public static void main(String[] a) {
    JFileChooser fileChooser = new JFileChooser(".");
    fileChooser.setAccessory(new LabelAccessory(fileChooser));
    int status = fileChooser.showOpenDialog(null);
    if (status == JFileChooser.APPROVE_OPTION) {
        File selectedFile = fileChooser.getSelectedFile();
        System.out.println(selectedFile.getParent());
        System.out.println(selectedFile.getName());
    } else if (status == JFileChooser.CANCEL_OPTION) {
        System.out.println("JFileChooser.CANCEL_OPTION");
    }/*from  www .  j  av  a  2 s  .  co m*/
}

From source file:Main.java

public static void main(String[] a) {
    JFileChooser fileChooser = new JFileChooser(".");
    FileFilter filter1 = new ExtensionFileFilter("JPG and JPEG", new String[] { "JPG", "JPEG" });
    fileChooser.setFileFilter(filter1);//from  ww  w .j  a  v  a 2  s  .  c  om
    int status = fileChooser.showOpenDialog(null);
    if (status == JFileChooser.APPROVE_OPTION) {
        File selectedFile = fileChooser.getSelectedFile();
        System.out.println(selectedFile.getParent());
        System.out.println(selectedFile.getName());
    } else if (status == JFileChooser.CANCEL_OPTION) {
        System.out.println(JFileChooser.CANCEL_OPTION);
    }
}

From source file:MainClass.java

public static void main(String[] a) {
    JFileChooser fileChooser = new JFileChooser(".");
    FileView view = new JavaFileView();
    fileChooser.setFileView(view);//from w  ww  . j a v  a  2s.c  om
    int status = fileChooser.showOpenDialog(null);
    if (status == JFileChooser.APPROVE_OPTION) {
        File selectedFile = fileChooser.getSelectedFile();
        System.out.println(selectedFile.getParent());
        System.out.println(selectedFile.getName());
    } else if (status == JFileChooser.CANCEL_OPTION) {
        System.out.println("JFileChooser.CANCEL_OPTION");
    }
}

From source file:AudioFilter.java

public static void main(String[] args) {
    AudioFilter audioFilter = new AudioFilter();

    JFileChooser jfc = new JFileChooser();

    jfc.setDialogTitle("Open File");
    jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    jfc.setCurrentDirectory(new File("."));
    jfc.setFileFilter(audioFilter);/*  w  w w .jav  a 2s .co m*/
    int result = jfc.showOpenDialog(null);

    if (result == JFileChooser.CANCEL_OPTION) {
        System.out.println("cancel");
    } else if (result == JFileChooser.APPROVE_OPTION) {
        File fFile = jfc.getSelectedFile();
        String filestr = fFile.getAbsolutePath();

        System.out.println(filestr);
    }
}

From source file:FileSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("JFileChooser Popup");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();

    final JLabel directoryLabel = new JLabel();
    contentPane.add(directoryLabel, BorderLayout.NORTH);

    final JLabel filenameLabel = new JLabel();
    contentPane.add(filenameLabel, BorderLayout.SOUTH);

    final JButton button = new JButton("Open FileChooser");
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            Component parent = (Component) actionEvent.getSource();
            JFileChooser fileChooser = new JFileChooser(".");
            fileChooser.setAccessory(new LabelAccessory(fileChooser));
            FileView view = new JavaFileView();
            fileChooser.setFileView(view);
            int status = fileChooser.showOpenDialog(parent);
            if (status == JFileChooser.APPROVE_OPTION) {
                File selectedFile = fileChooser.getSelectedFile();
                directoryLabel.setText(selectedFile.getParent());
                filenameLabel.setText(selectedFile.getName());
            } else if (status == JFileChooser.CANCEL_OPTION) {
                directoryLabel.setText(" ");
                filenameLabel.setText(" ");
            }//www .  j a va2  s.com
        }
    };
    button.addActionListener(actionListener);
    contentPane.add(button, BorderLayout.CENTER);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:FilterSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("JFileChooser Filter Popup");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();

    final JLabel directoryLabel = new JLabel();
    contentPane.add(directoryLabel, BorderLayout.NORTH);

    final JLabel filenameLabel = new JLabel();
    contentPane.add(filenameLabel, BorderLayout.SOUTH);

    final JButton button = new JButton("Open FileChooser");
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            Component parent = (Component) actionEvent.getSource();
            JFileChooser fileChooser = new JFileChooser(".");
            fileChooser.setAccessory(new LabelAccessory(fileChooser));
            FileFilter filter1 = new ExtensionFileFilter(null, new String[] { "JPG", "JPEG" });
            //        fileChooser.setFileFilter(filter1);
            fileChooser.addChoosableFileFilter(filter1);
            FileFilter filter2 = new ExtensionFileFilter("gif", new String[] { "gif" });
            fileChooser.addChoosableFileFilter(filter2);
            fileChooser.setFileView(new JavaFileView());
            int status = fileChooser.showOpenDialog(parent);
            if (status == JFileChooser.APPROVE_OPTION) {
                File selectedFile = fileChooser.getSelectedFile();
                directoryLabel.setText(selectedFile.getParent());
                filenameLabel.setText(selectedFile.getName());
            } else if (status == JFileChooser.CANCEL_OPTION) {
                directoryLabel.setText(" ");
                filenameLabel.setText(" ");
            }//from   w w w.  j a v  a  2 s .  c  o  m
        }
    };
    button.addActionListener(actionListener);
    contentPane.add(button, BorderLayout.CENTER);

    frame.setSize(300, 200);
    frame.setVisible(true);
}