Example usage for javax.swing JFileChooser getCurrentDirectory

List of usage examples for javax.swing JFileChooser getCurrentDirectory

Introduction

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

Prototype

public File getCurrentDirectory() 

Source Link

Document

Returns the current directory.

Usage

From source file:Main.java

public static void main(String[] argv) {
    final JFileChooser chooser = new JFileChooser();

    File curDir = chooser.getCurrentDirectory();
    chooser.setDialogTitle("" + curDir.getAbsolutePath());

    chooser.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals(evt.getPropertyName())) {
                File curDir = chooser.getCurrentDirectory();

                chooser.setDialogTitle("" + curDir.getAbsolutePath());
            }//  w  ww  .ja  va2 s  .  c  o m
        }
    });
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final JButton button = new JButton("Click me");
    button.addActionListener(e -> {/*from w  ww. j  ava  2s  .co m*/
        JFileChooser chooser = new JFileChooser();
        chooser.setSelectedFile(new File(chooser.getCurrentDirectory(), "save.dat"));
        final JTextField textField = getTexField(chooser);
        if (textField == null) {
            return;
        }
        String text = textField.getText();
        if (text == null) {
            return;
        }
        int index = text.lastIndexOf('.');
        if (index == -1) {
            return;
        }
        textField.setSelectionStart(0);
        textField.setSelectionEnd(index);

        chooser.showSaveDialog(button);

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

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JFileChooser chooser = new JFileChooser();
    File f = new File(new File(".").getCanonicalPath());
    chooser.setCurrentDirectory(f);/*from   w  w  w.  j  a  v  a  2s  .  c o m*/
    chooser.setCurrentDirectory(null);
    chooser.showOpenDialog(null);
    File curDir = chooser.getCurrentDirectory();
}

From source file:Main.java

public static void main(String s[]) {
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new java.io.File("."));
    chooser.setDialogTitle("choosertitle");
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setAcceptAllFileFilterUsed(false);

    if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        System.out.println("getCurrentDirectory(): " + chooser.getCurrentDirectory());
        System.out.println("getSelectedFile() : " + chooser.getSelectedFile());
    } else {//from   ww w  . j  a va2  s.  com
        System.out.println("No Selection ");
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    final JFileChooser chooser = new JFileChooser();

    chooser.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (JFileChooser.FILE_VIEW_CHANGED_PROPERTY.equals(evt.getPropertyName())) {
                JFileChooser chooser = (JFileChooser) evt.getSource();
                File oldDir = (File) evt.getOldValue();
                File newDir = (File) evt.getNewValue();

                File curDir = chooser.getCurrentDirectory();
            }//from   w  ww  .ja va  2 s . c  om
        }
    });
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    final JFileChooser chooser = new JFileChooser();

    chooser.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals(evt.getPropertyName())) {
                JFileChooser chooser = (JFileChooser) evt.getSource();
                File oldDir = (File) evt.getOldValue();
                File newDir = (File) evt.getNewValue();

                File curDir = chooser.getCurrentDirectory();
            }/*ww  w.  j  ava 2  s .co  m*/
        }
    });
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    final JFileChooser chooser = new JFileChooser();

    chooser.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (JFileChooser.ACCESSORY_CHANGED_PROPERTY.equals(evt.getPropertyName())) {
                JFileChooser chooser = (JFileChooser) evt.getSource();
                File oldDir = (File) evt.getOldValue();
                File newDir = (File) evt.getNewValue();

                File curDir = chooser.getCurrentDirectory();
            }//from ww  w  .  j  a v  a  2  s.  co  m
        }
    });
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    final JFileChooser chooser = new JFileChooser();

    chooser.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (JFileChooser.FILE_HIDING_CHANGED_PROPERTY.equals(evt.getPropertyName())) {
                JFileChooser chooser = (JFileChooser) evt.getSource();
                File oldDir = (File) evt.getOldValue();
                File newDir = (File) evt.getNewValue();

                File curDir = chooser.getCurrentDirectory();
            }//from w w w . ja v a  2  s.c  o m
        }
    });
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    final JFileChooser chooser = new JFileChooser();

    chooser.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (JFileChooser.DIALOG_TYPE_CHANGED_PROPERTY.equals(evt.getPropertyName())) {
                JFileChooser chooser = (JFileChooser) evt.getSource();
                File oldDir = (File) evt.getOldValue();
                File newDir = (File) evt.getNewValue();

                File curDir = chooser.getCurrentDirectory();
            }/*  w  w  w . j  a va 2  s . c o  m*/
        }
    });
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    final JFileChooser chooser = new JFileChooser();

    chooser.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (JFileChooser.FILE_FILTER_CHANGED_PROPERTY.equals(evt.getPropertyName())) {
                JFileChooser chooser = (JFileChooser) evt.getSource();
                File oldDir = (File) evt.getOldValue();
                File newDir = (File) evt.getNewValue();

                File curDir = chooser.getCurrentDirectory();
            }/*from  www  .  j  av  a  2 s. c  om*/
        }
    });
}