Example usage for javax.swing JFileChooser JFileChooser

List of usage examples for javax.swing JFileChooser JFileChooser

Introduction

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

Prototype

public JFileChooser(FileSystemView fsv) 

Source Link

Document

Constructs a JFileChooser using the given FileSystemView.

Usage

From source file:Main.java

public static void main(String[] argv) {
    JFileChooser fileChooser = new JFileChooser(".");
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
}

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  w  w w. j a v  a2s.  c  o m*/
}

From source file:Main.java

public static void main(String[] args) {
    JFileChooser fileChooser = new JFileChooser(".");
    fileChooser.setControlButtonsAreShown(false);
    fileChooser.setFileFilter(new FolderFilter());
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    fileChooser.showOpenDialog(null);/*from   www  .ja v a 2  s .c  om*/
}

From source file:Main.java

public static void main(String[] argv) {
    JFileChooser fileChooser = new JFileChooser(new File("."));
    fileChooser.addChoosableFileFilter(new MyFilter());

    fileChooser.showOpenDialog(null);//ww  w  .jav  a2 s  .  co  m
    System.out.println(fileChooser.getSelectedFile());

}

From source file:Main.java

public static void main(String[] args) {
    final JFileChooser chooser = new JFileChooser(new File(".")) {
        public void approveSelection() {
            if (getSelectedFile().exists()) {
                super.approveSelection();
            } else
                System.out.println("File doesn't exist");
        }/*from   w ww .jav a2 s  . c  om*/
    };

    chooser.addActionListener(e -> System.out.println(e));

    chooser.setSelectedFile(new File("something.txt"));
    int returnVal = chooser.showSaveDialog(null);

    if (returnVal == JFileChooser.APPROVE_OPTION) {
        System.out.println(chooser.getSelectedFile());
    }

}

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");
    }/* w  w w . ja  v  a  2 s  .  c  om*/
}

From source file:Main.java

public static void main(String[] argv) {
    String filename = File.separator + "tmp";
    JFileChooser fc = new JFileChooser(new File(filename));

    // Show open dialog
    fc.showOpenDialog(null);/* www  .  j  a v  a2  s.  c  om*/
    File selFile = fc.getSelectedFile();

    // Show save dialog
    fc.showSaveDialog(null);
    selFile = fc.getSelectedFile();

}

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);//  w w  w.  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: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 a  va2  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) {
    JFrame frame = new JFrame("JFileChooser Popup");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JFileChooser fileChooser = new JFileChooser(".");

    fileChooser.rescanCurrentDirectory();
    frame.add(fileChooser, BorderLayout.CENTER);

    frame.pack();/*from   w w w  . j av  a 2s  .  c  o m*/
    frame.setVisible(true);
}