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.biosis.biosislite.vistas.inventario.MantenimientoFactura.java

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    // TODO add your handling code here:
    JFileChooser fc = new JFileChooser();
    int respuesta = fc.showOpenDialog(this);
    if (respuesta == JFileChooser.APPROVE_OPTION) {
        File archivoElegido = fc.getSelectedFile();
        facturaField.setText(archivoElegido.getAbsolutePath());

        //            fotolbl.setIcon(new ImageIcon("C:/Users/Documentos/Desktop/HS/" + fotosField.getText()));
        ImageIcon fot = new ImageIcon(facturaField.getText());
        Icon icono = new ImageIcon(fot.getImage().getScaledInstance(lblFactura.getWidth(),
                lblFactura.getHeight(), Image.SCALE_DEFAULT));
        lblFactura.setIcon(icono);/*  www . j a v  a2s  . co m*/

    }
}

From source file:com.sec.ose.osi.ui.frm.main.manage.FileBrowser.java

public void actionPerformed(ActionEvent e) {

    JFCFolderExplorer explorer = JFCFolderExplorer.getInstance();
    JFileChooser chooser = explorer.getJFileChooser();
    String sFileLoc = getFileLocation();

    if ((sFileLoc == null) || (sFileLoc.length() == 0)) {
        chooser.setCurrentDirectory(new java.io.File(sDefaultPath));
    } else {//ww w .ja  v a 2 s. co m
        chooser.setCurrentDirectory(new java.io.File(sFileLoc));
    }

    int result = explorer.showBrowser(frmOwner);
    String path = "";
    if (result == JFileChooser.APPROVE_OPTION) {
        path = chooser.getSelectedFile().getAbsolutePath();
        if (projectInfo != null)
            projectInfo.setSourcePath(path);

        setFileLocation(path);

        if (projectModel != null)
            projectModel.forceRefreshTable();
    }

    if (sFileLoc == null || !sFileLoc.equals(path)) {
        log.debug("}}}}}}BEFORE{{{{{{ project status will change ---> " + projectInfo.getProjectName() + " : "
                + IdentifiedController.getProjectStatus(projectInfo.getProjectName()) + " : "
                + projectInfo.isSourcePathChange());
        projectInfo.setSourcePathChange(true);
        projectInfo.setAnalyzeTarget(true);
        projectModel.setProjectAnalysisStatus(projectInfo.getProjectName(), ProjectAnalysisInfo.STATUS_READY);
        IdentifiedController.setProjectStatus(projectInfo.getProjectName(), AnalysisMonitorThread.STATUS_READY);
        log.debug("}}}}}}AFTER{{{{{{ project status changed ---> " + projectInfo.getProjectName() + " : "
                + IdentifiedController.getProjectStatus(projectInfo.getProjectName()) + " : "
                + projectInfo.isSourcePathChange());
    } else {
        projectInfo.setSourcePathChange(false);
    }
}

From source file:ac.kaist.ccs.presentation.CCSHubSelectionCost.java

public CCSHubSelectionCost(final String title, Map<Integer, List<Double>> data) {

    super(title);
    this.title = title;
    final XYDataset dataset = createDataset(data);
    final JFreeChart chart = createChart(dataset);
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    final ChartPanel chartPanel = new ChartPanel(chart);

    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BorderLayout());
    JButton buttonExport = new JButton("Export");
    buttonPanel.add("East", buttonExport);
    buttonExport.addActionListener(new ActionListener() {
        ChartPanel chartPanel;//from  w w w.j  av  a  2s . c o m

        public ActionListener init(ChartPanel chartPanel) {
            this.chartPanel = chartPanel;
            return this;
        }

        @Override
        public void actionPerformed(ActionEvent arg0) {
            // TODO Auto-generated method stub
            Dimension size = chartPanel.getSize();

            try {
                //String outPath = textFieldSelectPath.getText();
                //String filename = "chromatography.png";
                //String path = outPath+"/"+filename;
                JFileChooser fileChooser = new JFileChooser();

                fileChooser.setCurrentDirectory(new File("/Users/mac/Desktop"));

                fileChooser.setFileFilter(new javax.swing.filechooser.FileNameExtensionFilter("JPEG", "jpeg"));

                int returnVal = fileChooser.showDialog(new JFrame(), "Open File Path");

                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    String inputPath = fileChooser.getSelectedFile().getAbsolutePath();
                    if (!inputPath.endsWith(".jpeg"))
                        inputPath = inputPath + ".jpeg";

                    OutputStream os = new FileOutputStream(inputPath);
                    System.out.println(inputPath + "///" + size.width + " " + size.height);
                    BufferedImage chartImage = chartPanel.getChart().createBufferedImage(size.width,
                            size.height, null);
                    ImageIO.write(chartImage, "png", os);
                    os.close();
                    JOptionPane.showMessageDialog(null, "Chart image was saved in " + inputPath);

                }

            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    }.init(chartPanel));

    panel.add("Center", chartPanel);
    panel.add("South", buttonPanel);

    chartPanel.setPreferredSize(new java.awt.Dimension(700, 500));
    setContentPane(panel);

}

From source file:de.biomedical_imaging.ij.plot.HistogramPlotter.java

public HistogramPlotter(String title, String xlabel, double[][] data, int numberOfParticles,
        int meanTrackLength, IDatasetCreator datacreator) {

    super(title);
    this.title = title;
    this.xlabel = xlabel;
    this.numberOfParticles = numberOfParticles;
    this.meanTrackLength = meanTrackLength;
    IntervalXYDataset xydataset = datacreator.create(data);
    boolean isbarplot = (datacreator instanceof BarplotDataset);
    txt = new JLabel();
    Font f = new Font("Verdana", Font.PLAIN, 12);
    txt.setFont(f);/*from   w w w  . ja v  a 2  s.  co m*/

    JFreeChart chart = createChart(xydataset, isbarplot);

    ChartPanel chartPanel = new ChartPanel(chart);

    txt.setText(formatSettingsString());

    main = new JPanel();
    main.setPreferredSize(new java.awt.Dimension(500, 350));
    main.add(chartPanel);
    main.add(txt);
    setContentPane(main);

    setLayout(new BoxLayout(main, BoxLayout.Y_AXIS));

    pack();
    setVisible(true);

    JMenuItem savebutton = ((JMenuItem) chartPanel.getPopupMenu().getComponent(3));
    chartPanel.getPopupMenu().remove(3); // Remove Save button
    //ActionListener al = savebutton.getActionListeners()[0];
    savebutton = new JMenuItem("Save as png");
    //savebutton.removeActionListener(al);
    savebutton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            // TODO Auto-generated method stub

            try {
                JFileChooser saveFile = new JFileChooser();
                saveFile.setAcceptAllFileFilterUsed(false);
                saveFile.addChoosableFileFilter(new FileNameExtensionFilter("Images", "png"));
                int userSelection = saveFile.showSaveDialog(main);
                if (userSelection == JFileChooser.APPROVE_OPTION) {
                    BufferedImage bi = ScreenImage.createImage(main);
                    File fileToSave = saveFile.getSelectedFile();
                    String filename = fileToSave.getName();
                    int i = filename.lastIndexOf('.');
                    String suffix = filename.substring(i + 1);
                    String path = fileToSave.getAbsolutePath();
                    if (!(suffix.equals("png"))) {
                        path += ".png";
                    }
                    ScreenImage.writeImage(bi, path);
                }
            } catch (IOException e) {
                // TODO Auto-generated catch block
                IJ.log("" + e.getMessage());
            }

        }
    });
    chartPanel.getPopupMenu().insert(savebutton, 3);

}

From source file:ch.bfh.lca._15h.server.gui.MainWindowServer.java

private void btnSetDatabasePathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSetDatabasePathActionPerformed

    // JFileChooser-Objekt erstellen
    JFileChooser chooser = new JFileChooser();
    // Dialog zum Speichern von Dateien anzeigen
    int resultValue = chooser.showDialog(null, "Bitte whle die SQLLite Datenbank aus");

    if (resultValue == JFileChooser.APPROVE_OPTION) {
        this.txtDatabasePath.setText(chooser.getSelectedFile().getAbsolutePath());
    }/*from   ww w . j a  v a2 s . co  m*/

}

From source file:com.titan.storagepanel.DownloadImageDialog.java

public DownloadImageDialog(final Frame frame) {
    super(frame, true);
    setTitle("Openstack vm os image");
    setBounds(100, 100, 947, 706);//from   w w  w.jav  a2 s. c om
    getContentPane().setLayout(new BorderLayout());
    contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    getContentPane().add(contentPanel, BorderLayout.CENTER);
    contentPanel.setLayout(new BorderLayout(0, 0));
    {
        JPanel panel = new JPanel();
        contentPanel.add(panel, BorderLayout.NORTH);
        panel.setLayout(new MigLayout("", "[41px][107.00px][27px][95.00px][24px][95.00px][]", "[27px]"));
        {
            JLabel lblSearch = new JLabel("Search");
            panel.add(lblSearch, "cell 0 0,alignx left,aligny center");
        }
        {
            searchTextField = new JSearchTextField();
            searchTextField.setPreferredSize(new Dimension(150, 40));
            panel.add(searchTextField, "cell 1 0,growx,aligny center");
        }
        {
            JLabel lblType = new JLabel("Type");
            panel.add(lblType, "cell 2 0,alignx left,aligny center");
        }
        {
            typeComboBox = new JComboBox(
                    new String[] { "All", "Ubuntu", "Fedora", "Redhat", "CentOS", "Gentoo", "Windows" });
            panel.add(typeComboBox, "cell 3 0,growx,aligny top");
        }
        {
            JLabel lblSize = new JLabel("Size");
            panel.add(lblSize, "cell 4 0,alignx left,aligny center");
        }
        {
            sizeComboBox = new JComboBox(new String[] { "0-700MB", ">700MB" });
            panel.add(sizeComboBox, "cell 5 0,growx,aligny top");
        }
        {
            JButton btnSearch = new JButton("Search");
            btnSearch.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    d.setVisible(true);
                }
            });
            panel.add(btnSearch, "cell 6 0");
        }
    }
    {
        JScrollPane scrollPane = new JScrollPane();
        contentPanel.add(scrollPane, BorderLayout.CENTER);
        {
            table = new JTable();
            table.setModel(tableModel);
            table.addMouseListener(new JTableButtonMouseListener(table));
            table.addMouseMotionListener(new JTableButtonMouseListener(table));
            scrollPane.setViewportView(table);
        }
    }
    {
        JPanel panel = new JPanel();
        getContentPane().add(panel, BorderLayout.SOUTH);
        {
            JButton downloadButton = new JButton("Download");
            downloadButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    if (table.getSelectedRowCount() == 1) {
                        JFileChooser jf = new JFileChooser();
                        int x = jf.showSaveDialog(frame);
                        if (x == JFileChooser.APPROVE_OPTION) {
                            DownloadImage p = (DownloadImage) table.getValueAt(table.getSelectedRow(), 0);
                            DownloadFileDialog d = new DownloadFileDialog(frame, "Downloading image", true,
                                    p.file, jf.getSelectedFile());
                            CommonLib.centerDialog(d);
                            d.setVisible(true);
                        }
                    }
                }
            });
            panel.add(downloadButton);
        }
    }

    d = new JProgressBarDialog(frame, true);
    d.progressBar.setIndeterminate(true);
    d.progressBar.setStringPainted(true);
    d.thread = new Thread() {
        public void run() {
            InputStream in = null;
            tableModel.columnNames.clear();
            tableModel.columnNames.add("image");
            tableModel.editables.clear();
            tableModel.editables.put(0, true);
            Vector<Object> col1 = new Vector<Object>();
            try {
                d.progressBar.setString("connecting to titan image site");
                in = new URL("http://titan-image.kingofcoders.com/titan-image.xml").openStream();
                String xml = IOUtils.toString(in);
                NodeList list = TitanCommonLib.getXPathNodeList(xml, "/images/image");
                for (int x = 0; x < list.getLength(); x++) {
                    DownloadImage downloadImage = new DownloadImage();
                    downloadImage.author = TitanCommonLib.getXPath(xml,
                            "/images/image[" + (x + 1) + "]/author/text()");
                    downloadImage.authorEmail = TitanCommonLib.getXPath(xml,
                            "/images/image[" + (x + 1) + "]/authorEmail/text()");
                    downloadImage.License = TitanCommonLib.getXPath(xml,
                            "/images/image[" + (x + 1) + "]/License/text()");
                    downloadImage.description = TitanCommonLib.getXPath(xml,
                            "/images/image[" + (x + 1) + "]/description/text()");
                    downloadImage.file = TitanCommonLib.getXPath(xml,
                            "/images/image[" + (x + 1) + "]/file/text()");
                    downloadImage.os = TitanCommonLib.getXPath(xml, "/images/image[" + (x + 1) + "]/os/text()");
                    downloadImage.osType = TitanCommonLib.getXPath(xml,
                            "/images/image[" + (x + 1) + "]/osType/text()");
                    downloadImage.uploadDate = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").parse(
                            TitanCommonLib.getXPath(xml, "/images/image[" + (x + 1) + "]/uploadDate/text()"));
                    downloadImage.size = TitanCommonLib.getXPath(xml,
                            "/images/image[" + (x + 1) + "]/size/text()");
                    downloadImage.architecture = TitanCommonLib.getXPath(xml,
                            "/images/image[" + (x + 1) + "]/architecture/text()");
                    col1.add(downloadImage);
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                JOptionPane.showMessageDialog(frame, "Unable to connect titan image site !", "Error",
                        JOptionPane.ERROR_MESSAGE);
            } finally {
                IOUtils.closeQuietly(in);
            }
            tableModel.values.clear();
            tableModel.values.add(col1);
            tableModel.fireTableStructureChanged();
            table.getColumnModel().getColumn(0).setCellRenderer(new DownloadImageTableCellRenderer());
            //            table.getColumnModel().getColumn(0).setCellEditor(new DownloadImageTableCellEditor());
            for (int x = 0; x < table.getRowCount(); x++) {
                table.setRowHeight(x, 150);
            }
        }
    };
    d.setVisible(true);
}

From source file:au.org.ala.delta.intkey.ui.DefineButtonDialog.java

@Action
public void DefineButtonDialog_Browse() {
    JFileChooser chooser = new JFileChooser();
    FileNameExtensionFilter filter = new FileNameExtensionFilter(fileFilterDescription,
            new String[] { "bmp", "png" });
    chooser.setFileFilter(filter);//from  w w  w  . j a v  a2  s . com

    int returnVal = chooser.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File selectedFile = chooser.getSelectedFile();
        _txtFldFileName.setText(selectedFile.getAbsolutePath());
    }
}

From source file:de.tntinteractive.portalsammler.gui.DocumentTable.java

private boolean exportDocument(final JFileChooser chooser, final int row) {
    try {//  w ww .  jav  a 2s.c  o  m
        final DocumentInfo di = this.getDocumentInRow(row);
        final byte[] content = this.store.getDocument(di);

        chooser.setSelectedFile(new File(this.makeFilenameFor(di)));
        final int result = chooser.showSaveDialog(this.table);
        if (result != JFileChooser.APPROVE_OPTION) {
            return true;
        }

        FileUtils.writeByteArrayToFile(chooser.getSelectedFile(), content);
        this.store.markAsRead(di);
        this.store.writeMetadata();
    } catch (final GeneralSecurityException e) {
        this.gui.showError(e);
    } catch (final IOException e) {
        this.gui.showError(e);
    }
    return false;
}

From source file:kg.apc.jmeter.vizualizers.SynthesisReportGui.java

@Override
public void actionPerformed(ActionEvent ev) {
    if (ev.getSource() == saveTable) {
        JFileChooser chooser = FileDialoger.promptToSaveFile("synthesis.csv");
        if (chooser == null) {
            return;
        }//from   ww  w . j av  a  2s. c  om
        FileWriter writer = null;
        try {
            writer = new FileWriter(chooser.getSelectedFile()); // TODO
            // Charset ?
            CSVSaveService.saveCSVStats(getAllTableData(model, FORMATS), writer,
                    saveHeaders.isSelected() ? getLabels(COLUMNS) : null);
        } catch (FileNotFoundException e) {
            log.warn(e.getMessage());
        } catch (IOException e) {
            log.warn(e.getMessage());
        } finally {
            JOrphanUtils.closeQuietly(writer);
        }
    }
}

From source file:baocaoxla.compare.java

private void btOutputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btOutputActionPerformed
    JFileChooser fc = new JFileChooser();
    fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    fc.showOpenDialog(this);
    File dir = fc.getSelectedFile();
    txtOutput.setText(dir.toString());//from   w  w  w. j ava 2 s .com
}