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() 

Source Link

Document

Constructs a JFileChooser pointing to the user's default directory.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JFileChooser chooser = new JFileChooser();
    File f = new File(new File("filename.txt").getCanonicalPath());

    chooser.setSelectedFiles(new File[] { f });

    chooser.showOpenDialog(null);/*from   w w w  .  j av a  2s  . c  o  m*/
    File curFile = chooser.getSelectedFile();
}

From source file:Main.java

public static void main(String[] args) {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setAcceptAllFileFilterUsed(false);
    FileNameExtensionFilter filter = new FileNameExtensionFilter("MPEG3 songs", "mp3");
    fileChooser.addChoosableFileFilter(filter);
    fileChooser.showOpenDialog(null);/*  ww w.j  a  va  2 s.co m*/

}

From source file:UsingFileSystemView.java

public static void main(String[] a) {

    JFileChooser chooser = new JFileChooser();

    FileSystemView view = chooser.getFileSystemView();

    System.out.println(view.getDefaultDirectory());

}

From source file:Main.java

License:asdf

public static void main(String[] argv) throws Exception {
    JFileChooser chooser = new JFileChooser();
    File f = new File(new File("filename.txt").getCanonicalPath());

    chooser.setDialogTitle("asdf");
    chooser.showDialog(new JFrame(""), null);
    File curFile = chooser.getSelectedFile();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JFileChooser chooser = new JFileChooser();
    File f = new File(new File("filename.txt").getCanonicalPath());

    chooser.setDialogType(JFileChooser.SAVE_DIALOG);
    chooser.showDialog(new JFrame(""), null);
    File curFile = chooser.getSelectedFile();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JFileChooser chooser = new JFileChooser();
    File f = new File(new File("filename.txt").getCanonicalPath());

    chooser.resetChoosableFileFilters();
    chooser.showDialog(new JFrame(""), null);
    File curFile = chooser.getSelectedFile();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JFileChooser chooser = new JFileChooser();
    File f = new File(new File("filename.txt").getCanonicalPath());

    chooser.setSelectedFiles(new File[] { f });
    chooser.showDialog(new JFrame(""), null);
    File curFile = chooser.getSelectedFile();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JFileChooser chooser = new JFileChooser();
    File f = new File(new File("filename.txt").getCanonicalPath());

    chooser.setDragEnabled(true);/*from   ww w  . j a  va 2 s  .c  o  m*/
    chooser.showDialog(new JFrame(""), null);
    File curFile = chooser.getSelectedFile();
}

From source file:Main.java

public static void main(String[] args) {

    JFileChooser chooser = new JFileChooser();
    FileSystemView view = chooser.getFileSystemView();

    System.out.println("The default directory is " + view.getDefaultDirectory());
}

From source file:Main.java

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

    if (a == JFileChooser.APPROVE_OPTION) {
        File fileToOpen = fileChooser.getSelectedFile();
        Desktop.getDesktop().open(fileToOpen);
    }// w w  w .j a v  a 2s .  co  m
}