Example usage for javax.swing JFileChooser getSelectedFile

List of usage examples for javax.swing JFileChooser getSelectedFile

Introduction

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

Prototype

public File getSelectedFile() 

Source Link

Document

Returns the selected file.

Usage

From source file:com.seanmadden.net.fast.FastInterpretype.java

public boolean saveLogToFile() {
    JFileChooser jfc = new JFileChooser();
    FileNameExtensionFilter filter = new FileNameExtensionFilter("Text Files", "txt");
    jfc.setFileFilter(filter);//from w  w  w .  j  a  v a 2  s. co  m
    int retVal = jfc.showSaveDialog(null);
    if (retVal == JFileChooser.APPROVE_OPTION) {
        String filename = jfc.getSelectedFile().getPath();
        mw.saveWindowToFile(filename);
        return true;
    }
    return false;
}

From source file:de.burrotinto.jKabel.dbauswahlAS.DBAuswahlAAS.java

private String choosePath(String pfad) {
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new java.io.File(pfad));
    chooser.setDialogTitle("DB Pfad");
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setAcceptAllFileFilterUsed(false);
    return chooser.showOpenDialog(null) != JFileChooser.APPROVE_OPTION ? null
            : chooser.getSelectedFile().getPath() + File.separator;

}

From source file:it.unibas.spicygui.controllo.file.ActionSaveAsMappingTask.java

@Override
public void performAction() {
    Scenario scenario = (Scenario) modello.getBean(Costanti.CURRENT_SCENARIO);
    MappingTask mappingTask = scenario.getMappingTask();
    JFileChooser chooser = vista.getFileChooserSalvaXmlXsd();
    continua = true;//from   w  w w .j  a  va  2 s.  co m
    File file;
    while (continua) {
        int returnVal = chooser.showSaveDialog(WindowManager.getDefault().getMainWindow());
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            try {
                file = chooser.getSelectedFile();
                if (!file.exists()) {
                    daoMappingTask.saveMappingTask(mappingTask, file.getAbsolutePath());
                    mappingTask.setModified(false);
                    mappingTask.setToBeSaved(false);
                    continua = false;
                    esito = true;
                } else {
                    chiediConferma(file, mappingTask);
                }
            } catch (DAOException ex) {
                DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
                        NbBundle.getMessage(Costanti.class, Costanti.SAVE_ERROR) + " : " + ex.getMessage(),
                        DialogDescriptor.ERROR_MESSAGE));
                logger.error(ex);
                continua = false;
                esito = false;
            }
        } else {
            continua = false;
            esito = false;
        }
    }
}

From source file:fusion.Fusion.java

private static void setSameAsLinksFile() throws IOException {

    JFileChooser dialogue = new JFileChooser(new File("."));
    File fichier;//from w  w  w .  j  av a 2 s  . c om

    if (dialogue.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        fichier = dialogue.getSelectedFile();
        sameAsLinksFile = fichier.getPath();
    }
}

From source file:fusion.Fusion.java

private static void setDatasetFile1() throws IOException {

    JFileChooser dialogue = new JFileChooser(new File("."));
    File fichier;//from ww w  .  j a va  2  s  . co m

    if (dialogue.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        fichier = dialogue.getSelectedFile();
        datasetFile1 = fichier.getPath();
    }
}

From source file:fusion.Fusion.java

private static void setDatasetFile2() throws IOException {

    JFileChooser dialogue = new JFileChooser(new File("."));
    File fichier;// w  w w. ja  v a  2s .c  om

    if (dialogue.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        fichier = dialogue.getSelectedFile();
        datasetFile2 = fichier.getPath();
    }
}

From source file:Result3.java

public void createImage() {
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new File("Documents"));
    int retrival = chooser.showSaveDialog(null);
    if (retrival == JFileChooser.APPROVE_OPTION) {
        try {//w w w  .j a  v  a  2s . c  o m
            ImageIO.write(bImage1, "png", new File(chooser.getSelectedFile() + ".png"));
        } catch (IOException ex) {
            Logger.getLogger(Result1.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:Result3.java

public void createImageJPG() {
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new File("Documents"));
    int retrival = chooser.showSaveDialog(null);
    if (retrival == JFileChooser.APPROVE_OPTION) {
        try {/* w w w  .j ava 2 s  .  c om*/
            ImageIO.write(bImage1, "jpg", new File(chooser.getSelectedFile() + ".jpg"));
        } catch (IOException ex) {
            Logger.getLogger(Result1.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:modelibra.swing.app.util.FileSelector.java

/**
 * Gets the opened file given a file path.
 * // w  w  w. ja  va 2s.  c o m
 * @param path
 *            path
 * @param lang
 *            language
 * @return file
 */
public File getOpenFile(String path, NatLang lang) {
    File selectedFile = null;
    File currentFile = null;
    if (path != null && !path.equalsIgnoreCase("?")) {
        currentFile = new File(path);
    } else
        currentFile = lastOpenedFile;

    JFileChooser chooser = new JFileChooser();
    chooser.setLocale(lang.getLocale());
    if (currentFile != null) {
        chooser.setCurrentDirectory(currentFile);
    }
    int returnVal = chooser.showOpenDialog(chooser);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        selectedFile = chooser.getSelectedFile();
    }
    lastOpenedFile = selectedFile;

    return selectedFile;
}

From source file:ec.util.chart.swing.Charts.java

public static void saveChart(@Nonnull ChartPanel chartPanel) throws IOException {
    JFileChooser fileChooser = new JFileChooser();
    FileFilter defaultFilter = new FileNameExtensionFilter("PNG (.png)", "png");
    fileChooser.addChoosableFileFilter(defaultFilter);
    fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("JPG (.jpg) (.jpeg)", "jpg", "jpeg"));
    if (Charts.canWriteChartAsSVG()) {
        fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("SVG (.svg)", "svg"));
        fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("Compressed SVG (.svgz)", "svgz"));
    }/*from  w w w .ja va2s .com*/
    fileChooser.setFileFilter(defaultFilter);
    File currentDir = chartPanel.getDefaultDirectoryForSaveAs();
    if (currentDir != null) {
        fileChooser.setCurrentDirectory(currentDir);
    }
    if (fileChooser.showSaveDialog(chartPanel) == JFileChooser.APPROVE_OPTION) {
        File file = fileChooser.getSelectedFile();
        try (OutputStream stream = Files.newOutputStream(file.toPath())) {
            writeChart(getMediaType(file), stream, chartPanel.getChart(), chartPanel.getWidth(),
                    chartPanel.getHeight());
        }
        chartPanel.setDefaultDirectoryForSaveAs(fileChooser.getCurrentDirectory());
    }
}