Example usage for javax.swing JFileChooser setCurrentDirectory

List of usage examples for javax.swing JFileChooser setCurrentDirectory

Introduction

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

Prototype

@BeanProperty(preferred = true, description = "The directory that the JFileChooser is showing files of.")
public void setCurrentDirectory(File dir) 

Source Link

Document

Sets the current directory.

Usage

From source file:org.kuali.test.creator.TestCreator.java

private void handleBackupRepository() {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setCurrentDirectory(new File(System.getProperty("user.home")));
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int result = fileChooser.showOpenDialog(this);
    if (result == JFileChooser.APPROVE_OPTION) {
        final File selectedFile = fileChooser.getSelectedFile();

        new SplashDisplay(this, "Back Up", "Backing up repository...") {
            @Override/*from   w  w w.j a va 2s. c o  m*/
            protected void runProcess() {
                try {
                    new ZipDirectory(new File(getConfiguration().getRepositoryLocation()),
                            getBackupFile(selectedFile));
                }

                catch (Exception ex) {
                    LOG.error(ex.toString(), ex);
                }
            }
        };
    }
}

From source file:org.languagetool.gui.Tools.java

private static File openFileDialog(Frame frame, FileFilter fileFilter, File initialDir, int mode) {
    JFileChooser jfc = new JFileChooser();
    jfc.setFileSelectionMode(mode);/*w ww .  j  a va  2s.  c  o m*/
    jfc.setCurrentDirectory(initialDir);
    jfc.setFileFilter(fileFilter);
    jfc.showOpenDialog(frame);
    return jfc.getSelectedFile();
}

From source file:org.mbari.aved.ui.utils.VideoUtils.java

/**
 * Browse for video clip, or still image archive starting in last imported directory
 *///from  ww w.j  a  va2  s  .  c  o m
public static File browseForImageSource(File setCurrentDirectory) throws Exception {
    File f = null;

    // Add a custom file filter and disable the default
    JFileChooser chooser = new JFileChooser();

    chooser.addChoosableFileFilter(new ImageFileFilter());
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.setDialogTitle("Choose Still Image/Video Source File");
    chooser.setCurrentDirectory(setCurrentDirectory);

    if (chooser.showOpenDialog(Application.getView()) == JFileChooser.APPROVE_OPTION) {
        f = chooser.getSelectedFile();
        UserPreferences.getModel().setImportVideoDir(f.getParent());
    } else {

        // TODO: print dialog message box with something meaningful here
        System.out.println("No Selection ");

        return null;
    }

    return f;
}

From source file:org.n52.ifgicopter.spf.input.GpxInputPlugin.java

/**
 * // w w  w .  ja  v  a2  s. c  o m
 */
protected void selectGpxFileAction() {
    EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
            JFileChooser fc = new JFileChooser();
            fc.setDialogTitle("Select GPX File");
            fc.setFileFilter(new FileFilter() {

                @Override
                public boolean accept(File f) {
                    if (f.getName().toLowerCase().endsWith("gpx") || f.getName().toLowerCase().endsWith("xml"))
                        return true;
                    if (f.isDirectory())
                        return true;

                    return false;
                }

                @Override
                public String getDescription() {
                    return "GPX file";
                }
            });
            File gpxfile = new File(getGpxFilePath());
            if (gpxfile.isFile()) {
                fc.setCurrentDirectory(gpxfile.getParentFile());
            }

            int returnVal = fc.showOpenDialog(getUserInterface().getGui());

            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                setGpxFilePath(file.getAbsolutePath());
            } else {
                getLog().debug("Open command cancelled by user.");
            }

            fc = null;
        }
    });
}

From source file:org.n52.ifgicopter.spf.output.GpxOutputPlugin.java

/**
 * /*from w w  w . j  a  v a 2  s. c o m*/
 */
protected void selectGpxFileAction() {
    EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
            JFileChooser fc = new JFileChooser();
            fc.setDialogTitle("Select GPX File");
            fc.setFileFilter(new FileFilter() {

                @Override
                public boolean accept(File f) {
                    if (f.getName().toLowerCase().endsWith("gpx") || f.getName().toLowerCase().endsWith("xml"))
                        return true;
                    if (f.isDirectory())
                        return true;

                    return false;
                }

                @Override
                public String getDescription() {
                    return "GPX file";
                }
            });

            File gpxfile = new File(getGpxFilePath());
            if (gpxfile.isFile()) {
                fc.setCurrentDirectory(gpxfile.getParentFile());
            }

            int returnVal = fc.showOpenDialog(getUserInterface().getGui());

            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                if (!file.getName().endsWith(".gpx") || !file.getName().endsWith(".xml"))
                    setGpxFilePath(file.getAbsolutePath() + ".gpx");
                else
                    setGpxFilePath(file.getAbsolutePath());
            } else {
                log.debug("Open command cancelled by user.");
            }

            fc = null;
        }
    });
}

From source file:org.neo4j.desktop.ui.BrowseForDatabaseActionListener.java

private File fileSelection() {
    File selectedFile = null;/*from   w  w w .  j a v a2 s  .c  om*/

    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode(DIRECTORIES_ONLY);
    fileChooser.setCurrentDirectory(new File(directoryDisplay.getText()));
    fileChooser.setDialogTitle("Select database");
    fileChooser.setDialogType(CUSTOM_DIALOG);

    int choice = fileChooser.showOpenDialog(frame);

    if (choice == APPROVE_OPTION) {
        selectedFile = fileChooser.getSelectedFile();
    }

    return selectedFile;
}

From source file:org.p_vcd.ui.VcdDialog.java

private void selectFileButton() {
    JFileChooser fc = new JFileChooser();
    fc.setMultiSelectionEnabled(false);/*from www. j  a v  a 2 s. c o  m*/
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setFileFilter(
            new FileNameExtensionFilter("images and videos", Parameters.get().getImageAndVideoExtensions()));
    File def = Parameters.get().getDefaultDir_QuerySelection();
    if (def != null)
        fc.setCurrentDirectory(def);
    int returnVal = fc.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        Parameters.get().updateDefaultDir_QuerySelection(fc.getCurrentDirectory());
        queryFile = fc.getSelectedFile();
        lbl_queryFile.setText(queryFile.getAbsolutePath());
        radio_queryFile.setSelected(true);
    }
}

From source file:org.richie.codeGen.ui.CodeGenMainUI.java

/**
 * /*from w  ww.j  a  va2s .c  om*/
 */
private void openPdmFile() {
    JFileChooser jfc = new JFileChooser();// 
    LastOperateVo lastOperateVo = null;
    try {
        lastOperateVo = GlobalData.getLastOperateVo();
    } catch (Exception e2) {
        log.error("??", e2);
    }
    if (lastOperateVo != null && lastOperateVo.getPdmFilePath() != null) {
        jfc.setCurrentDirectory(new File(lastOperateVo.getPdmFilePath()));// ?d
    } else {
        jfc.setCurrentDirectory(new File("d:\\"));// ?d

    }
    jfc.setFileSelectionMode(0);// ?
    jfc.setFileFilter(new FileFilter() {

        public boolean accept(File f) {
            if (f.getName().endsWith(".pdm") || f.isDirectory()) {
                return true;
            }
            return false;
        }

        public String getDescription() {
            return "pdm(*.pdm)";
        }
    });
    int state = jfc.showOpenDialog(null);
    if (state == 1) {
        return;
    } else {
        File f = jfc.getSelectedFile();
        initTree(f.getAbsolutePath());
        try {
            if (lastOperateVo == null) {
                lastOperateVo = new LastOperateVo();
            }
            lastOperateVo.setPdmFilePath(f.getAbsolutePath());
            GlobalData.saveLastOperateVo();
        } catch (Exception e1) {
            log.error("???pdm", e1);
        }
    }
}

From source file:org.richie.codeGen.ui.configui.ConstantConfigWin.java

@Override
public void actionPerformed(ActionEvent e) {
    if (e.getSource() == addLineBtn) {
        ConstantConfigVo vo = new ConstantConfigVo();
        constantConfigModel.addRow(vo);//ww w . ja  v  a2 s. co m
        table.updateUI();
    } else if (e.getSource() == saveBtn) {
        onSave();
    } else if (e.getSource() == chooseBtn1 || e.getSource() == chooseBtn2 || e.getSource() == chooseBtn3
            || e.getSource() == chooseBtn4) {
        JFileChooser jfc = new JFileChooser();// 
        if (e.getSource() == chooseBtn1) {
            jfc.setCurrentDirectory(new File(rootPathValue1.getText()));
        } else if (e.getSource() == chooseBtn2) {
            jfc.setCurrentDirectory(new File(rootPathValue2.getText()));
        } else if (e.getSource() == chooseBtn3) {
            jfc.setCurrentDirectory(new File(rootPathValue3.getText()));
        } else if (e.getSource() == chooseBtn4) {
            jfc.setCurrentDirectory(new File(rootPathValue4.getText()));
        }
        jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);// ?
        int status = jfc.showOpenDialog(this);
        if (status == JFileChooser.CANCEL_OPTION) {
            return;
        } else {
            File file = jfc.getSelectedFile();
            if (e.getSource() == chooseBtn1) {
                rootPathValue1.setText(file.getAbsolutePath());
            } else if (e.getSource() == chooseBtn2) {
                rootPathValue2.setText(file.getAbsolutePath());
            } else if (e.getSource() == chooseBtn3) {
                rootPathValue3.setText(file.getAbsolutePath());
            } else if (e.getSource() == chooseBtn4) {
                rootPathValue4.setText(file.getAbsolutePath());
            }
        }
    }

}

From source file:org.signserver.admin.gui.AddWorkerDialog.java

private void filePathBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_filePathBrowseButtonActionPerformed
    final JFileChooser chooser = new JFileChooser();
    final File baseDir = SignServerAdminGUIApplication.getBaseDir();
    final String basedirPath = baseDir.getAbsolutePath();
    final File sampleDir = new File(basedirPath + File.separator + "doc" + File.separator + "sample-configs");

    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setCurrentDirectory(sampleDir.isDirectory() ? sampleDir : baseDir);
    chooser.setFileFilter(new FileNameExtensionFilter("Properties files", "properties"));

    final int res = chooser.showOpenDialog(this);

    if (res == JFileChooser.APPROVE_OPTION) {
        final File file = chooser.getSelectedFile();
        filePathTextField.setText(file.getAbsolutePath());
        fileSelected = true;//w ww . ja  v  a2  s. c  o  m
    }

    updateControls();
}