Example usage for javax.swing JFileChooser showOpenDialog

List of usage examples for javax.swing JFileChooser showOpenDialog

Introduction

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

Prototype

public int showOpenDialog(Component parent) throws HeadlessException 

Source Link

Document

Pops up an "Open File" file chooser dialog.

Usage

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);
    File selFile = fc.getSelectedFile();

    // Show save dialog
    fc.showSaveDialog(null);/* w  ww.j a va  2s. c  o m*/
    selFile = fc.getSelectedFile();

}

From source file:JFileChooserHidingFiles.java

public static void main(String[] a) {

    JFileChooser fileChooser = new JFileChooser();

    fileChooser.setFileHidingEnabled(false);

    fileChooser.showOpenDialog(null);
}

From source file:Main.java

public static void main(String[] argv) {
    JFileChooser chooser = new JFileChooser();
    boolean enabled = chooser.isFileSelectionEnabled();

    chooser.showOpenDialog(null);
}

From source file:Main.java

public static void main(String[] argv) {
    JFileChooser chooser = new JFileChooser();
    boolean enabled = chooser.isMultiSelectionEnabled();

    chooser.showOpenDialog(null);
}

From source file:ActionListenerTest3.java

public static void main(String[] args) {
    JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JButton button = new JButton("Select File");
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser fileChooser = new JFileChooser();
            int returnVal = fileChooser.showOpenDialog(null);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                System.out.println(fileChooser.getSelectedFile().getName());
            }/*from  www .  ja va2  s  . com*/
        }
    });

    frame.add(button);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) {
    JFileChooser chooser = new JFileChooser();
    boolean enabled = chooser.isAcceptAllFileFilterUsed();

    chooser.showOpenDialog(null);
}

From source file:Main.java

public static void main(String[] argv) {
    JFileChooser chooser = new JFileChooser();
    boolean enabled = chooser.isDirectorySelectionEnabled();

    chooser.showOpenDialog(null);
}

From source file:JFileChooserTest.java

public static void main(String[] args) {
    JFrame.setDefaultLookAndFeelDecorated(true);
    JDialog.setDefaultLookAndFeelDecorated(true);
    JFrame frame = new JFrame("JComboBox Test");
    frame.setLayout(new FlowLayout());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JButton button = new JButton("Select File");
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            JFileChooser fileChooser = new JFileChooser();
            int returnValue = fileChooser.showOpenDialog(null);
            if (returnValue == JFileChooser.APPROVE_OPTION) {
                File selectedFile = fileChooser.getSelectedFile();
                System.out.println(selectedFile.getName());
            }/*from  w  ww. jav  a  2  s.  c  o  m*/
        }
    });
    frame.add(button);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) {
    JFileChooser chooser = new JFileChooser();
    boolean enabled = chooser.isTraversable(new File("abc"));

    chooser.showOpenDialog(null);
}

From source file:Main.java

public static void main(String s[]) {
    JFileChooser chooser = new JFileChooser();
    disableNewFolderButton(chooser);/*from w  w  w .  j av a 2  s .  c  o  m*/
    int rc = chooser.showOpenDialog(null);
}