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:de.hstsoft.sdeep.view.MainWindow.java

private void openFileChooser() {

    final JFileChooser fileChooser = new JFileChooser(new File("."));
    int retVal = fileChooser.showOpenDialog(this);
    if (retVal == JFileChooser.APPROVE_OPTION) {
        File selectedFile = fileChooser.getSelectedFile();
        openFile(selectedFile);//w w w.  jav a2 s . c  o m
    }

}

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

@Override
public void performAction() {
    this.executeInjection();
    JFileChooser chooser = vista.getFileChooserApriTGD();
    File file;/*w  w  w  .j  av  a  2s.c  o m*/
    int returnVal = chooser.showOpenDialog(WindowManager.getDefault().getMainWindow());
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        try {
            file = chooser.getSelectedFile();
            String fileAbsoluteFile = file.getPath();
            ParseMappingTask generator = new ParseMappingTask();
            //giannisk
            Scenarios.getNextFreeNumber();
            MappingTask mappingTask = generator.generateMappingTask(fileAbsoluteFile);
            gestioneScenario(mappingTask);
            this.actionViewSchema.performAction();
            enableActions();
        } catch (Exception ex) {
            DialogDisplayer.getDefault()
                    .notify(new NotifyDescriptor.Message(
                            NbBundle.getMessage(Costanti.class, Costanti.OPEN_ERROR) + " : " + ex.getMessage(),
                            DialogDescriptor.ERROR_MESSAGE));
            logger.error(ex);
        }
    }
}

From source file:avoking.com.documentos.scheduler.startup.Main.java

public String getPathDocs(JFileChooser fc) {
    fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

    int opc = fc.showOpenDialog(null);
    if (opc == JFileChooser.APPROVE_OPTION) {
        File f = fc.getSelectedFile();
        if (f != null) {
            if (f.isDirectory())
                return f.getAbsolutePath();
            else/*from w ww .  j  a va2 s . com*/
                return f.getParentFile().getAbsolutePath();
        } else {
            //                JOptionPane.showMessageDialog(null, "Selecciona una ruta valida!!", "Directorio incorrecto", JOptionPane.WARNING_MESSAGE);
            return "";
        }
    } else
        return "";
}

From source file:com.jtk.medicalrecord.view.panel.InputMedrecPemeriksaanpendukung.java

private void btnTambahActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTambahActionPerformed
    if (view) {//from  w  ww.  jav  a2 s .  c o m
        download();
    } else {
        JFileChooser fileChooser = new JFileChooser();
        int result = fileChooser.showOpenDialog(null);
        if (result == JFileChooser.APPROVE_OPTION) {
            String url = fileChooser.getSelectedFile().getAbsolutePath();
            try {
                InputStream is = new FileInputStream(new File(url));
                String tipeFile = FilenameUtils.getExtension(url);
                String namaFile = FilenameUtils.getBaseName(url);

                PemeriksaanPendukung pp = new PemeriksaanPendukung();
                pp.setPemId(UUID.randomUUID().toString().replace("-", ""));
                pp.setPemNmFile(namaFile);
                pp.setPemTipeFile(tipeFile);
                pp.setPemFile(IOUtils.toByteArray(is));

                pemeriksaanPendukungs.add(pp);

                createTableValue();
            } catch (FileNotFoundException ex) {
                MessageHelper.addErrorMessage("Error add file", ex.getMessage());
                Logger.getLogger(InputMedrecPemeriksaanpendukung.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                MessageHelper.addErrorMessage("Error add file", ex.getMessage());
                Logger.getLogger(InputMedrecPemeriksaanpendukung.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}

From source file:cmsc105_mp2.Plot.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new File("Documents"));
    int retrival = chooser.showSaveDialog(null);
    if (retrival == JFileChooser.APPROVE_OPTION) {
        try {/*w w w . jav  a  2 s  .c  om*/
            ImageIO.write(bImage1, "png", new File(chooser.getSelectedFile() + ".png"));
        } catch (IOException ex) {
            System.out.println("Unable to Print!");
        }
    }
}

From source file:EscribirCorreo.java

private void subir1FieldMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_subir1FieldMousePressed
    // TODO add your handling code here:
    // Buscar archivo para subir
    JFileChooser subir = new JFileChooser();
    int opcion = subir.showOpenDialog(null);
    if (opcion == JFileChooser.APPROVE_OPTION) {
        archivo = subir.getSelectedFile().getPath();
        nombre = subir.getSelectedFile().getName();
        subir1Field.setText(archivo);

    }/*from w ww .  j  a va  2  s.c om*/
}

From source file:net.mitnet.tools.pdf.book.publisher.ui.gui.BaseBookPublisherGUI.java

protected void browseFile(JTextField dirField) {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    int returnVal = fileChooser.showOpenDialog(null);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File selectedFile = fileChooser.getSelectedFile();
        String selectedFilePath = selectedFile.getAbsolutePath();
        dirField.setText(selectedFilePath);
    }//from w ww . ja  va2s.  c o  m
}

From source file:com.decypher.threadsclient.JPanelChart.java

private String getFolder() {
    JFileChooser folderPick = new JFileChooser();
    folderPick.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    folderPick.setDialogType(JFileChooser.SAVE_DIALOG);
    folderPick.setMultiSelectionEnabled(false);
    String selected;// w  w w.ja v a  2  s. c  om
    int returnVal = folderPick.showOpenDialog(null);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        selected = folderPick.getSelectedFile().getPath();
    } else {
        selected = "";
    }
    return selected;
}

From source file:net.mitnet.tools.pdf.book.publisher.ui.gui.BaseBookPublisherGUI.java

protected void browseDir(JTextField dirField) {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int returnVal = fileChooser.showOpenDialog(null);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File selectedFile = fileChooser.getSelectedFile();
        String selectedFilePath = selectedFile.getAbsolutePath();
        dirField.setText(selectedFilePath);
    }//from   w  w  w.  j  a va 2s .  c  o m
}

From source file:com.itd.dbmrgdao.TestTime3_backup.java

@Ignore
@org.junit.Test/*from w w  w.  j av a  2 s . c  om*/
public void test() throws ParseException {
    String newTab = "\t";
    String[] sysidLine;

    JFileChooser chooser = new JFileChooser();
    FileNameExtensionFilter filter = new FileNameExtensionFilter("Text File", "txt");
    chooser.setFileFilter(filter);
    chooser.showOpenDialog(null);
    File f = chooser.getSelectedFile();

    String filename = f.getAbsolutePath();
    try {
        FileReader reader = new FileReader(filename);
        BufferedReader br = new BufferedReader(reader);
        String strLine;

        String sysid = null, p1Start = null, p1End = null, p2Start = null, p2End = null, otStart = null,
                otEnd = null;
        Date scdate = null;

        // read from select file
        while ((strLine = br.readLine()) != null) {
            String[] parts = strLine.split(" ");

            // check if not first record or sysid change will save in table scandata 
            if (sysid != null && !sysid.equals(parts[0])) {
                // rule if whatever employee register will get standard hour 8 hrs
                if (p1Start != null || p2End != null) {
                    ScanRule scanRule = scanDao.findScanRuleBySysId(sysid);
                    p1Start = scanRule.getP1start();
                    p2End = scanRule.getP2end();
                }

                // set up data in entity
                ScanDataKey scanDataKey = new ScanDataKey(sysid, scdate);
                ScanData scanData = new ScanData(scanDataKey, "1985", p1Start, p1End, p2Start, p2End, otStart,
                        otEnd);
                // remove old record (key is sysid and scdate)
                gennericDao.remove(scanData);
                gennericDao.create(scanData);

                //clear 
                p1Start = null;
                p1End = null;
                p2Start = null;
                p2End = null;
                otStart = null;
                otEnd = null;

            }

            sysid = parts[0];
            scdate = new SimpleDateFormat("yyyyMMdd", Locale.US).parse(parts[1]);

            if (parts[6].equals("01")) {
                p1Start = CompareTime(p1Start, parts[5], "01");
            } else {
                p2End = CompareTime(p2End, parts[5], "04");
            }

        }
        //last line

        if (p1Start != null || p2End != null) {
            ScanRule scanRule = scanDao.findScanRuleBySysId(sysid);
            p1Start = scanRule.getP1start();
            p2End = scanRule.getP2end();
        }

        ScanDataKey scanDataKey = new ScanDataKey(sysid, scdate);
        ScanData scanData = new ScanData(scanDataKey, "1985", p1Start, p1End, p2Start, p2End, otStart, otEnd);
        gennericDao.remove(scanData);
        gennericDao.create(scanData);

        br.close();

    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e);
    }

}