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.github.cmisbox.ui.UI.java

public File getWatchFolder() {
    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.showOpenDialog(null);//ww  w .  j  a  va 2  s. c o  m
    return chooser.getSelectedFile();
}

From source file:firmadigital.Parametros.java

private void cmdExaminarAlmacenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdExaminarAlmacenActionPerformed
    JFileChooser fileChooser = new JFileChooser();
    if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        String selectedFile = fileChooser.getSelectedFile().getAbsolutePath();
        txtUbicacionAlmacenCertificado.setText(selectedFile);
    }/*from   w  w  w  .j av a2  s  .c  om*/
}

From source file:firmadigital.Parametros.java

private void cmdExaminarCertificadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdExaminarCertificadoActionPerformed
    JFileChooser fileChooser = new JFileChooser();
    if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        String selectedFile = fileChooser.getSelectedFile().getAbsolutePath();
        txtCertificado.setText(selectedFile);
    }// w w w  .jav  a 2  s.c  om
}

From source file:MainWindow.java

public MainWindow() {
    // Login Routine
    loginDialog = new LoginDialog();
    // loginDialog.nameField.setText("cornelius.preidel@googlemail.com");
    // loginDialog.passwordField.setText("germany");
    loginDialog.setSize(400, 150);//from ww w .j  av a  2s  .co  m
    loginDialog.setModal(true);
    loginDialog.setLocationRelativeTo(null);
    loginDialog.setVisible(true);

    // Get the connected ApiCore
    core = loginDialog._core;

    // Init the UI
    mainFrame = new JFrame("MainApplication");
    mainFrame.setSize(500, 500);
    mainFrame.setLocationRelativeTo(null);
    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    mainFrame.setLayout(new GridLayout(5, 1));

    // WebProjectsList webprojectlist = new WebProjectsList(core);
    // mainFrame.add(webprojectlist);

    // Create the APIS
    Teams teamsAPI = new Teams(core);
    final Projects projectsAPI = new Projects(core);
    final Divisions divisionsAPI = new Divisions(core);
    final Attachments attachmentAPI = new Attachments(core);
    final Issues issueAPI = new Issues(core);

    // TEAMS List
    TeamsList teamList = new TeamsList();
    teamList.setTeams(teamsAPI.GetTeams());
    mainFrame.add(teamList);

    // PROJECTS  List
    projectsList = new ProjectsList();
    mainFrame.add(projectsList);

    // DIVISIONS List
    divisionsList = new DivisionsList();
    // mainFrame.add(divisionsList);

    // DIVISIONS Table
    divisionsTable = new DivisionsTable(core);
    mainFrame.add(divisionsTable);

    // Attachments
    attachmentsList = new AttachmentsList();
    mainFrame.add(attachmentsList);

    // Attachments
    issuesList = new IssuesList();
    mainFrame.add(issuesList);

    PropertyChangeListener propertyChangeListener = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
            String property = propertyChangeEvent.getPropertyName();
            if ("selectedTeam".equals(property)) {
                DtoTeam selectedTeam = (DtoTeam) propertyChangeEvent.getNewValue();

                // Set the global slug
                core.currentTeam = selectedTeam;
                projectsList.setProjects(projectsAPI.GetProjects());
            } else if ("selectedProject".equals(property)) {
                DtoProject selectedProject = (DtoProject) propertyChangeEvent.getNewValue();
                // Divisions
                divisionsList.setDivisions(divisionsAPI.GetDivisions(selectedProject.GetId()));
                divisionsTable.setDivisions(divisionsAPI.GetDivisions(selectedProject.GetId()));
                // Attachments
                attachmentsList.setAttachments(attachmentAPI.GetAttachments(selectedProject.GetId()));
                // Issues
                issuesList.setIssues(issueAPI.GetIssues(selectedProject.GetId()));
            } else if ("selectedDivision".equals(property)) {
                DtoDivision selectedDivision = (DtoDivision) propertyChangeEvent.getNewValue();
                // What to do with the division?
            } else if ("selectedIssue".equals(property)) {
                DtoIssue selectedDivision = (DtoIssue) propertyChangeEvent.getNewValue();
                // What to do with the division?
            } else {
                if ("selectedAttachment".equals(property)) {
                    DtoAttachment selectedAttachment = (DtoAttachment) propertyChangeEvent.getNewValue();
                    InputStream stream = attachmentAPI.DownloadAttachment(selectedAttachment.GetId());

                    try {
                        byte[] bytes = IOUtils.toByteArray(stream);
                        JFileChooser chooser = new JFileChooser();
                        int returnVal = chooser.showSaveDialog(chooser);
                        File file = chooser.getSelectedFile();

                        FileOutputStream fos = new FileOutputStream(file);
                        fos.write(bytes);
                        fos.flush();
                        fos.close();
                    } catch (IOException e) {
                        LOG.error(e.getMessage(), e);
                    }
                }
            }
        }
    };

    // Add Listener
    teamList.addPropertyChangeListener(propertyChangeListener);
    projectsList.addPropertyChangeListener(propertyChangeListener);
    divisionsList.addPropertyChangeListener(propertyChangeListener);
    divisionsTable.addPropertyChangeListener(propertyChangeListener);
    attachmentsList.addPropertyChangeListener(propertyChangeListener);
    issuesList.addPropertyChangeListener(propertyChangeListener);
}

From source file:csv.to.sql.parser.mainMenu.java

private void btnOpenFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOpenFileActionPerformed
    // TODO add your handling code here:
    JFileChooser myFile = new JFileChooser();
    myFile.setFileFilter(new FileNameExtensionFilter("CSV Files", "csv"));
    myFile.showOpenDialog(this);
    this.selectedFile = myFile.getSelectedFile();
    if (this.selectedFile.exists()) {
        this.fileSelected = true;
        this.lblFile.setText(this.selectedFile.getName());
        this.btnOpenFile.setEnabled(false);
        this.btnParse.setEnabled(true);
    } else {//www.  j a  va  2 s  .c o m
        JOptionPane.showInternalMessageDialog(this, "The file doesn't exists!");
    }

}

From source file:ZipTest.java

public ZipTestFrame() {
    setTitle("ZipTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    // add the menu and the Open and Exit menu items
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("File");

    JMenuItem openItem = new JMenuItem("Open");
    menu.add(openItem);/*from   w w w .  j  av  a2  s  .com*/
    openItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            JFileChooser chooser = new JFileChooser();
            chooser.setCurrentDirectory(new File("."));
            int r = chooser.showOpenDialog(ZipTestFrame.this);
            if (r == JFileChooser.APPROVE_OPTION) {
                zipname = chooser.getSelectedFile().getPath();
                fileCombo.removeAllItems();
                scanZipFile();
            }
        }
    });

    JMenuItem exitItem = new JMenuItem("Exit");
    menu.add(exitItem);
    exitItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            System.exit(0);
        }
    });

    menuBar.add(menu);
    setJMenuBar(menuBar);

    // add the text area and combo box
    fileText = new JTextArea();
    fileCombo = new JComboBox();
    fileCombo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            loadZipFile((String) fileCombo.getSelectedItem());
        }
    });

    add(fileCombo, BorderLayout.SOUTH);
    add(new JScrollPane(fileText), BorderLayout.CENTER);
}

From source file:org.vimarsha.ui.DataLoaderForm.java

public DataLoaderForm() {

    for (String str : UIHandler.getInstance().getArchitectureList()) {
        architectureComboBox.addItem(str);
        architectureComboBox.setSelectedItem(null);
    }//from  www.  j a v  a 2  s  .co m

    architectureComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            UIHandler.getInstance().setArchitecture((String) architectureComboBox.getSelectedItem());
            trainingModelTextBox.setText(UIHandler.getInstance().getTrainingModel());
        }
    });
    openRAWFileButton.addActionListener(new ActionListener() {
        File file = null;

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            JFileChooser fc = new JFileChooser(".");
            int returnVal = fc.showOpenDialog(Tab0);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                file = fc.getSelectedFile();
            }
            if ((UIHandler.getInstance().setRawFile(file) == 100)
                    && (UIHandler.getInstance().convertRawToArff() == 100)) {
                saveToARFFFileButton.setEnabled(true);
                attributeList.setListData(UIHandler.getInstance().getArffAttribiutesTableModel().toArray());
                testDataTextField.setText(UIHandler.getInstance().getTestDataName());
            }

        }
    });
    openARFFFileButton.addActionListener(new ActionListener() {
        File file = null;

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            JFileChooser fc = new JFileChooser(".");
            int returnVal = fc.showOpenDialog(Tab0);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                file = fc.getSelectedFile();
                UIHandler.getInstance().setArffFile(file);
                attributeList.setListData(UIHandler.getInstance().getArffAttribiutesTableModel().toArray());
                saveToARFFFileButton.setEnabled(true);
                testDataTextField.setText(UIHandler.getInstance().getTestDataName());
            }

        }
    });
    saveToARFFFileButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            File file = null;
            JFileChooser fc = new JFileChooser(".");
            int returnVal = fc.showSaveDialog(Tab0);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                System.out.println(fc.getSelectedFile());
                UIHandler.getInstance().saveAsArff(fc.getSelectedFile());
            }

        }
    });

    attributeList.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent listSelectionEvent) {
            int selectedEvent = attributeList.getSelectedIndex();
            attributesSummaryTable
                    .setModel(UIHandler.getInstance().getArffAttributeInfo(attributeList.getSelectedIndex()));
            DefaultCategoryDataset data = UIHandler.getInstance().getBarChartDataSet(selectedEvent);
            drawBarChart(data);
        }
    });
}

From source file:it.unibas.spicygui.controllo.preprocessing.ActionUnpivotCSV.java

@Override
public void performAction() {
    this.executeInjection();
    JFileChooser chooser = vista.getFileChooserApriCSV();
    File file;//from ww w.  j a  v  a  2s  . co m
    int returnVal = chooser.showOpenDialog(WindowManager.getDefault().getMainWindow());
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        file = chooser.getSelectedFile();
        //file extension
        String ext = file.getPath().substring(file.getPath().lastIndexOf(".") + 1);
        if (ext.equalsIgnoreCase("csv")) {
            UnpivotCSVDAO daoUnpivot = new UnpivotCSVDAO();
            try {
                //                    avenet 20170410 
                //                    String[] columnNames = daoUnpivot.getCsvTableColumns(file);
                String[] columnNames = daoUnpivot.getCsvTableColumnsWithoutSpecialCharacters(file);
                UnpivotCsvMainFrame unpivotMain = new UnpivotCsvMainFrame(columnNames);
                List<String> colNames = unpivotMain.getColNames();
                List<String> keepColNames = unpivotMain.getKeepColNames();
                String newColName = unpivotMain.getNewColName();
                if (!colNames.isEmpty() && newColName != null && !newColName.equals("")) {
                    try {
                        daoUnpivot.unpivotTable(keepColNames, colNames, newColName, file);
                        DialogDisplayer.getDefault()
                                .notify(new NotifyDescriptor.Message(
                                        NbBundle.getMessage(Costanti.class, Costanti.EXPORT_UNPIVOTED_OK)
                                                + file.getParent()));
                    } catch (DAOException ex) {
                        DialogDisplayer.getDefault().notify(
                                new NotifyDescriptor.Message(ex.getMessage(), DialogDescriptor.ERROR_MESSAGE));
                        logger.error(ex);
                    } catch (SQLException ex) {
                        DialogDisplayer.getDefault().notify(
                                new NotifyDescriptor.Message(ex.getMessage(), DialogDescriptor.ERROR_MESSAGE));
                        logger.error(ex);
                    }
                }
            } catch (IOException ex) {
                DialogDisplayer.getDefault()
                        .notify(new NotifyDescriptor.Message(ex.getMessage(), DialogDescriptor.ERROR_MESSAGE));
            }
        } else {
            DialogDisplayer.getDefault()
                    .notify(new NotifyDescriptor.Message(
                            NbBundle.getMessage(Costanti.class, Costanti.MESSAGE_WRONG_FILE_INPUT) + ": \""
                                    + ext + "\"",
                            DialogDescriptor.ERROR_MESSAGE));
        }
    }
}

From source file:uk.co.petertribble.jkstat.gui.KstatBaseChartFrame.java

/**
 * Saves the current chart as an image in png format. The user can select
 * the filename, and is asked to confirm the overwrite of an existing file.
 *///from  ww w.  java  2s  . c o m
public void saveImage() {
    JFileChooser fc = new JFileChooser();
    if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
        File f = fc.getSelectedFile();
        if (f.exists()) {
            int ok = JOptionPane.showConfirmDialog(this,
                    KstatResources.getString("SAVEAS.OVERWRITE.TEXT") + " " + f.toString(),
                    KstatResources.getString("SAVEAS.CONFIRM.TEXT"), JOptionPane.YES_NO_OPTION);
            if (ok != JOptionPane.YES_OPTION) {
                return;
            }
        }
        BufferedImage bi = kbc.getChart().createBufferedImage(500, 300);
        try {
            ImageIO.write(bi, "png", f);
            /*
             * According to the API docs this should throw an IOException
             * on error, but this doesn't seem to be the case. As a result
             * it's necessary to catch exceptions more generally. Even this
             * doesn't work properly, but at least we manage to convey the
             * message to the user that the write failed, even if the
             * error itself isn't handled.
             */
        } catch (Exception ioe) {
            JOptionPane.showMessageDialog(this, ioe.toString(), KstatResources.getString("SAVEAS.ERROR.TEXT"),
                    JOptionPane.ERROR_MESSAGE);
        }
    }
}

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

@Ignore
@org.junit.Test/*from   w ww  .ja  v  a2 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, scdate = null, p1Start = null, p1End = null, p2Start = null, p2End = null,
                otStart = null, otEnd = null;

        StringBuilder mySql = new StringBuilder(
                "INSERT INTO scandata(sc_sysid,sc_scode,scdate,p1start,p1end,p2start,p2end,otstart,otend) VALUES (?,?,?,?,?,?,?,?,?)");

        while ((strLine = br.readLine()) != null) {
            String[] parts = strLine.split(" ");

            if (sysid != null && !sysid.equals(parts[0])) {
                mySql = mySql.append(", (").append(sysid).append(",\"1985\"").append(",").append(scdate)
                        .append(",").append(p1Start).append(",").append(p1End).append(",").append(p2Start)
                        .append(",").append(p2End).append(",").append(otStart).append(",").append(otEnd)
                        .append(")");

                //                    if (p1Start != null || p2End != null) {
                //                        ScanRule scanRule = scanDao.findScanRuleBySysId(sysid);
                //                        p1Start = scanRule.getP1start();
                //                        p2End = scanRule.getP2end();
                //                    }
                //                    ScanDataTest scanData = new ScanDataTest(sysid, scdate, p1Start, p2End);

                p1Start = null;
                p2End = null;

            }

            sysid = parts[0];
            scdate = 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();
        //            }
        //            ScanDataTest scanData = new ScanDataTest(sysid, scdate, p1Start, p2End);
        //            System.out.println(scanData);
        br.close();

    } catch (Exception e) {

        JOptionPane.showMessageDialog(null, e);

    }

}