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.sciaps.view.SpectrometerStackPanel.java

public void getRegionTextFile() {

    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileFilter(new FileNameExtensionFilter("Text files", "txt", "TXT"));
    int retval = fileChooser.showOpenDialog(Constants.MAIN_FRAME);

    if (retval == JFileChooser.APPROVE_OPTION) {
        File file = fileChooser.getSelectedFile();

        try {// w  ww.j a  v  a 2  s  . co  m
            FileReader fr = new FileReader(file.getAbsoluteFile());
            BufferedReader br = new BufferedReader(fr);

            StringBuilder text = new StringBuilder();
            String line;
            while ((line = br.readLine()) != null) {
                text.append(line);
            }

            br.close();

            createRegionItem(text.toString());

        } catch (FileNotFoundException ex) {
            showErrorDialog(ex.getMessage());
        } catch (IOException ex) {
            showErrorDialog(ex.getMessage());
        }

    }

}

From source file:com.smanempat.controller.ControllerClassification.java

public void saveResultFile(JYearChooser thnAjaran1, JYearChooser thnAjaran2, JTable tableResult)
        throws IOException {
    JFileChooser dirChooser = new JFileChooser();
    dirChooser.setDialogTitle("Save as Excel File");
    String thnAjaran = Integer.toString(thnAjaran1.getYear()) + "-" + Integer.toString(thnAjaran2.getYear());
    String generateFileName = "Data Hasil Penjurusan Siswa Tahun Ajaran " + thnAjaran + ".xlsx";
    dirChooser.setSelectedFile(new File(generateFileName));
    int userSelection = dirChooser.showSaveDialog(null);
    int rowCountData = tableResult.getRowCount();
    if (userSelection == dirChooser.APPROVE_OPTION) {
        File fileToSave = dirChooser.getSelectedFile();
        convertToExcel(tableResult, fileToSave);
        JOptionPane.showMessageDialog(null, "Hasil klasifikasi jurusan berhasil disimpan",
                "Penyimpanan Berhasil", JOptionPane.INFORMATION_MESSAGE,
                new ImageIcon("src/com/smanempat/image/success.png"));
    }//from   w  w w .  j av  a  2s.co m
}

From source file:com.ejie.uda.jsonI18nEditor.Editor.java

public void showImportDialog() {
    String path = null;//from  w  ww  .j  a v a 2 s. co m
    if (resourcesDir != null) {
        path = resourcesDir.toString();
    }
    JFileChooser fc = new JFileChooser(path);
    fc.setDialogTitle(MessageBundle.get("dialogs.import.title"));
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setFileFilter(new FileNameExtensionFilter("json i18n file", "json"));
    int result = fc.showOpenDialog(this);
    if (result == JFileChooser.APPROVE_OPTION) {
        importResources(Paths.get(fc.getSelectedFile().getPath()));
    }
}

From source file:de.evaluationtool.gui.EvaluationFrameActionListener.java

private void savePositiveNegativeNT() throws IOException {
    JFileChooser chooser = new JFileChooser("Save as multiple nt files. Please choose a directory");
    chooser.setCurrentDirectory(frame.defaultDirectory);
    if (geoFile != null) {
        chooser.setCurrentDirectory(geoFile);
    }//from  www .ja  v a  2  s  . c om
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setAcceptAllFileFilterUsed(false);

    int returnVal = chooser.showSaveDialog(frame);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        frame.savePositiveNegativeNT(chooser.getSelectedFile());
    }
}

From source file:org.nekorp.workflow.desktop.view.AppLayoutView.java

private void reporteGlobalButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reporteGlobalButtonActionPerformed
    try {//from  w w w .j  a  v  a2s.c  o m
        parametrosReporteGlobal.setFechaInicial(new Date());
        parametrosReporteGlobal.setFechaFinal(new Date());
        parametrosReporteGlobalDialogFactory.createDialog(mainFrame, true).setVisible(true);
        if (parametrosReporteGlobal.isEjecutar()) {
            JFileChooser chooser = new JFileChooser();
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Hojas de clculo", "xlsx");
            chooser.setFileFilter(filter);
            String homePath = System.getProperty("user.home");
            File f = new File(new File(homePath + "/Reporte-Global" + ".xlsx").getCanonicalPath());
            chooser.setSelectedFile(f);
            int returnVal = chooser.showSaveDialog(this.mainFrame);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
                ParametrosReporteGlobal param = new ParametrosReporteGlobal();
                param.setDestination(chooser.getSelectedFile());
                DateTime fechaInicial = new DateTime(parametrosReporteGlobal.getFechaInicial());
                DateTime fechaFinal = new DateTime(parametrosReporteGlobal.getFechaFinal());
                fechaFinal = new DateTime(fechaFinal.getYear(), fechaFinal.getMonthOfYear(),
                        fechaFinal.getDayOfMonth(), fechaFinal.hourOfDay().getMaximumValue(),
                        fechaFinal.minuteOfHour().getMaximumValue(),
                        fechaFinal.secondOfMinute().getMaximumValue(),
                        fechaFinal.millisOfSecond().getMaximumValue(), fechaFinal.getZone());
                param.setFechaInicial(fechaInicial);
                param.setFechaFinal(fechaFinal);
                this.aplication.generaReporteGlobal(param);
            }
        }
    } catch (IOException ex) {
        AppLayoutView.LOGGER.error("Exploto al tratar de generar el reporte global", ex);
    } finally {
        this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
    }
}

From source file:fll.subjective.SubjectiveFrame.java

/**
 * Prompt the user for a file.//from   www  .  java 2  s  . c o  m
 * 
 * @param title the title on the chooser dialog
 * @return the file if accepted, null if canceled
 */
private File chooseSubjectiveFile(final String title) {
    final File initialDirectory = getInitialDirectory();
    final JFileChooser fileChooser = new JFileChooser(initialDirectory);
    fileChooser.setDialogTitle(title);
    fileChooser.setFileFilter(new BasicFileFilter("FLL Subjective Data Files", "fll"));
    final int state = fileChooser.showOpenDialog(this);
    if (JFileChooser.APPROVE_OPTION == state) {
        final File file = fileChooser.getSelectedFile();
        setInitialDirectory(file);
        return file;
    } else {
        return null;
    }
}

From source file:biz.wolschon.finance.jgnucash.panels.TaxReportPanel.java

/**
 * Show a dialog to export// w w  w.ja  v a  2 s.c om
 * a CSV-file that contains the
 * shown {@link TransactionSum}s
 * for each month, year or day.
 */
protected void showExportCSVDialog() {
    JFileChooser fc = new JFileChooser();
    fc.setAcceptAllFileFilterUsed(true);
    fc.addChoosableFileFilter(new FileFilter() {

        @Override
        public boolean accept(final File aF) {
            return aF.isDirectory() || aF.getName().endsWith(".csv");
        }

        @Override
        public String getDescription() {
            return "CSV-file";
        }
    });
    int dialogResult = fc.showSaveDialog(this);
    if (dialogResult != JFileChooser.APPROVE_OPTION) {
        return;
    }
    File file = fc.getSelectedFile();
    if (file.exists()) {
        int confirmation = JOptionPane.showConfirmDialog(this, "File exists. Replace file?");
        if (confirmation != JOptionPane.YES_OPTION) {
            showExportCSVDialog();
            return;
        }
    }
    ExportGranularities gran = (ExportGranularities) myExportGranularityCombobox.getSelectedItem();
    try {
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        exportCSV(file, gran);
    } finally {
        setCursor(Cursor.getDefaultCursor());
    }
}

From source file:de.codesourcery.jasm16.ide.ui.views.ProjectConfigurationView.java

@Override
protected JPanel getPanel() {
    final JPanel result = new JPanel();
    result.setLayout(new GridBagLayout());

    // project name
    int y = 0;//from www  .  java2  s .  c  o  m
    GridBagConstraints cnstrs = constraints(0, y, false, false, GridBagConstraints.NONE);
    result.add(new JLabel("Project name"), cnstrs);

    cnstrs = constraints(1, y++, true, false, GridBagConstraints.NONE);
    result.add(projectName, cnstrs);

    // build options panel
    final JPanel buildOptionsPanel = new JPanel();
    buildOptionsPanel.setLayout(new GridBagLayout());

    buildOptionsPanel.setBorder(BorderFactory.createTitledBorder("Build options"));

    cnstrs = constraints(0, 0, false, false, GridBagConstraints.NONE);
    buildOptionsPanel.add(new JLabel("Compilation root"), cnstrs);

    cnstrs = constraints(1, 0, false, false, GridBagConstraints.NONE);
    compilationRootName.setEditable(false);
    compilationRootName.setColumns(25);
    buildOptionsPanel.add(compilationRootName, cnstrs);

    cnstrs = constraints(2, 0, true, false, GridBagConstraints.NONE);
    buildOptionsPanel.add(compilationRootButton, cnstrs);

    compilationRootButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final JFileChooser chooser;
            File baseDir = null;
            if (project != null) {
                baseDir = project.getConfiguration().getBaseDirectory();
            }
            if (StringUtils.isNotBlank(compilationRootName.getText())) {
                File tmp = new File(compilationRootName.getText()).getParentFile();
                if (tmp.exists() && tmp.isDirectory()) {
                    baseDir = tmp;
                }
            }
            if (baseDir != null) {
                chooser = new JFileChooser(baseDir);
            } else {
                chooser = new JFileChooser();
            }
            final int result = chooser.showOpenDialog(null);
            if (result == JFileChooser.APPROVE_OPTION && chooser.getSelectedFile().isFile()) {
                compilationRootName.setText(chooser.getSelectedFile().getAbsolutePath());
            }
        }
    });

    // generate self-relocating code ?
    cnstrs = constraints(0, 1, false, false, GridBagConstraints.NONE);
    buildOptionsPanel.add(new JLabel("Generate self-relocating code?"), cnstrs);

    cnstrs = constraints(1, 1, true, true, GridBagConstraints.NONE);
    cnstrs.gridwidth = 2;
    buildOptionsPanel.add(generateSelfRelocatingCode, cnstrs);

    // inline short literals ?
    cnstrs = constraints(0, 2, false, false, GridBagConstraints.NONE);
    buildOptionsPanel.add(new JLabel("Inline short literals?"), cnstrs);

    cnstrs = constraints(1, 2, true, true, GridBagConstraints.NONE);
    cnstrs.gridwidth = 2;
    buildOptionsPanel.add(inlineShortLiterals, cnstrs);

    // add build options panel to parent
    cnstrs = constraints(0, y++, true, false, GridBagConstraints.BOTH);
    cnstrs.gridwidth = 2;
    result.add(buildOptionsPanel, cnstrs);

    // buttons
    final JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridBagLayout());

    cnstrs = constraints(0, 0, false, false, GridBagConstraints.NONE);
    buttonPanel.add(saveButton, cnstrs);
    saveButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (hasValidInput()) {
                onSave();
            }
        }
    });

    cnstrs = constraints(1, 0, true, true, GridBagConstraints.NONE);
    buttonPanel.add(cancelButton, cnstrs);
    cancelButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            onCancel();
        }
    });

    // button panel
    cnstrs = constraints(0, y++, true, true, GridBagConstraints.NONE);
    cnstrs.gridwidth = 2;
    result.add(buttonPanel, cnstrs);

    return result;
}

From source file:ispd.gui.JResultados.java

private void jButtonSalvarTracesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSalvarTracesActionPerformed
    FiltroDeArquivos filtro = new FiltroDeArquivos("Workload Model of Simulation", ".wmsx", true);
    JFileChooser jFileChooser = new JFileChooser();
    jFileChooser.setFileFilter(filtro);//from   w ww.  jav  a 2  s.c  o m
    int returnVal = jFileChooser.showSaveDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = jFileChooser.getSelectedFile();
        if (!file.getName().endsWith(".wmsx")) {
            File temp = new File(file.toString() + ".wmsx");
            file = temp;
        }
        TraceXML interpret = new TraceXML(file.getAbsolutePath());
        interpret.geraTraceSim(tarefas);
    }
}

From source file:com.unsa.view.MainView.java

private void btnGuardarEnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarEnActionPerformed
    // TODO add your handling code here:
    JFileChooser jF1 = new javax.swing.JFileChooser();
    String ruta = "";
    try {/*w w w.  ja  va 2s.c o m*/
        if (jF1.showSaveDialog(null) == jF1.APPROVE_OPTION) {
            ruta = jF1.getSelectedFile().getAbsolutePath();
            //Aqui ya tiens la ruta,,,ahora puedes crear un fichero n esa ruta y escribir lo k kieras...
            jTextField1.setText(ruta);
        }

    } catch (Exception ex) {
        ex.printStackTrace();
    }

}