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:net.sf.maltcms.chromaui.ui.PaintScalePanel.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    JFileChooser jfc = new JFileChooser();
    int ret = jfc.showOpenDialog(getParent());
    if (ret == JFileChooser.APPROVE_OPTION) {
        File f = jfc.getSelectedFile();
        GradientPaintScale gps = new GradientPaintScale(getSampleTable(samples), 0, 1,
                ImageTools.rampToColorArray(new ColorRampReader().readColorRamp(f.getAbsolutePath())));
        gps.setLabel(f.getName());//from   w  w  w.  j a  v  a  2  s. co m
        dcbm.addElement(gps);
        dcbm.setSelectedItem(gps);
    }
}

From source file:Import.pnl_import_vcf.java

private void chooseFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseFileActionPerformed
    try {// w  ww .  j  a  v a 2 s. c o  m
        // TODO add your handling code here:
        filePathField.setText(null);
        JFileChooser chooser = new JFileChooser();
        chooser.showOpenDialog(null);
        String filePath = chooser.getSelectedFile().getAbsolutePath();
        filePathField.setText(filePath);
        DefaultDualListModel dualModel = new DefaultDualListModel();
        columnFamily.family c = new family();
        String[] columns = c.columnfamily(filePath);
        ArrayList<String> families = new ArrayList<>();
        for (int i = 0; i < columns.length; i++) {
            if (i > 7 && !columns[i].equalsIgnoreCase("FORMAT")) {
                families.add(columns[i] + ", SampleFamily");
            } else if (columns[i].equalsIgnoreCase("INFO")) {
                families.add(columns[i] + ", INFOFamily");
            } else if (!columns[i].equalsIgnoreCase("FORMAT")) {
                families.add(columns[i] + ", SingleColumn");
            }
        }
        for (String b : families) {
            dualModel.addElement(b);
        }
        list_dual_hbase_column_family.setModel(dualModel);
    } catch (HeadlessException | IOException ex) {
        Logger.getLogger(pnl_create_hive_link.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:kihira.tails.client.gui.GuiExport.java

@Override
protected void actionPerformed(GuiButton button) {
    //Export to file
    if (button.id == 0 || button.id == 1 || button.id == 2) {
        AbstractClientPlayer player = this.mc.thePlayer;
        File file;/*from w ww  . ja v a 2 s .  c o  m*/

        this.exportMessage = "";
        this.exportLoc = null;
        if (button.id == 0)
            file = new File(System.getProperty("user.home"));
        else if (button.id == 1)
            file = new File(System.getProperty("user.dir"));
        else {
            JFileChooser fileChooser = new JFileChooser(new File(System.getProperty("user.dir")));
            fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            if (fileChooser.showSaveDialog(Display.getParent()) == JFileChooser.APPROVE_OPTION) {
                file = fileChooser.getSelectedFile();
            } else
                return;
        }

        if (file.exists() && file.canWrite()) {
            this.exportLoc = file.toURI();
            file = new File(file, File.separatorChar + player.getCommandSenderName() + ".png");

            if (!file.exists()) {
                try {
                    file.createNewFile();
                } catch (IOException e) {
                    setExportMessage(
                            EnumChatFormatting.DARK_RED + String.format("Failed to create skin file! %s", e));
                    e.printStackTrace();
                }
            }

            BufferedImage image = TextureHelper.writePartsDataToSkin(this.partsData, player);
            if (image != null) {
                try {
                    ImageIO.write(image, "png", file);
                } catch (IOException e) {
                    setExportMessage(
                            EnumChatFormatting.DARK_RED + String.format("Failed to save skin file! %s", e));
                    e.printStackTrace();
                }
            } else {
                setExportMessage(
                        EnumChatFormatting.DARK_RED + String.format("Failed to export skin, image was null!"));
                file.delete();
            }
        }

        if (Strings.isNullOrEmpty(this.exportMessage)) {
            savePartsData();
            this.openFolderButton.visible = true;
            setExportMessage(EnumChatFormatting.GREEN + I18n.format("tails.export.success", file));
        }
    }
    if (button.id == 3 && this.exportLoc != null) {
        try {
            Desktop.getDesktop().browse(this.exportLoc);
        } catch (IOException e) {
            setExportMessage(
                    EnumChatFormatting.DARK_RED + String.format("Failed to open export location: %s", e));
            e.printStackTrace();
        }
    }

    //Upload
    if (button.id == 10) {
        final BufferedImage image = TextureHelper.writePartsDataToSkin(this.partsData, this.mc.thePlayer);
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                exportMessage = I18n.format("tails.uploading");
                new ImgurUpload().uploadImage(image);
            }
        };
        runnable.run();
    }
}

From source file:biometricgui.MainWindow.java

private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MouseClicked
    // TODO add your handling code here:
    JFileChooser videochooser = new JFileChooser();
    videochooser.showOpenDialog(null);//from   ww w  .j ava  2s .c o m
    File f = videochooser.getSelectedFile();
    runMedia(f.getAbsolutePath());
}

From source file:biometricgui.MainWindow.java

private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
    // TODO add your handling code here:
    JFileChooser videochooser = new JFileChooser();
    videochooser.showOpenDialog(null);/*from w  w  w .j ava  2  s.  co m*/
    File f = videochooser.getSelectedFile();
    runMedia(f.getAbsolutePath());

}

From source file:com.original.widget.OPicture.java

/**
 * very simple method to select an image file.
 * Please be advised that we will create our own file chooser in the
 * near future. Since in our system, people will be not encouraged to
 * access the physical file.//from  www.  ja  v a2  s.c o  m
 *
 * Of course, we need to discuss how to handle this issue.
 * @return
 */

private File chooseImgFile() {
    JFileChooser chooser = new JFileChooser(".");
    FileFilter imgType = new OriExtFileFilter("Image files", new String[] { ".jpg", ".gif", ".jpeg", ".png" });
    chooser.addChoosableFileFilter(imgType);
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.setFileFilter(imgType);
    int status = chooser.showOpenDialog(null);
    if (status == JFileChooser.APPROVE_OPTION) {
        File f = chooser.getSelectedFile();
        return f;
    }
    return null;
}

From source file:IHM.FenetreAjoutPhoto.java

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

    JFileChooser chooser = new JFileChooser(new File("."));

    chooser.setDialogTitle("ouvrir une image");

    int reponse = chooser.showOpenDialog(this);

    if (reponse == JFileChooser.APPROVE_OPTION) {

        InputStream input = null;

        f = chooser.getSelectedFile();

        nomPhoto = f.getName();//from  w  w w  .ja  va2 s  .  c  o m
        nomF = f.getAbsolutePath();

        txtNomPhoto.setText(nomPhoto);

    }

}

From source file:it.unibas.spicygui.controllo.mapping.ActionGenerateAndTranslate.java

private void checkForPKConstraints(MappingTask mappingTask, HashSet<String> pkTableNames, int scenarioNo)
        throws DAOException {
    if (!pkTableNames.isEmpty()) {
        NotifyDescriptor notifyDescriptor = new NotifyDescriptor.Confirmation(
                NbBundle.getMessage(Costanti.class, Costanti.MESSAGE_PK_TABLES),
                DialogDescriptor.YES_NO_OPTION);
        DialogDisplayer.getDefault().notify(notifyDescriptor);
        if (notifyDescriptor.getValue().equals(NotifyDescriptor.YES_OPTION)) {
            String[] format = { NbBundle.getMessage(Costanti.class, Costanti.OUTPUT_TYPE_CSV),
                    NbBundle.getMessage(Costanti.class, Costanti.OUTPUT_TYPE_JSON) };
            int formatResponse = JOptionPane.showOptionDialog(null,
                    NbBundle.getMessage(Costanti.class, Costanti.MESSAGE_PK_OUTPUT),
                    NbBundle.getMessage(Costanti.class, Costanti.PK_OUTPUT_TITLE), JOptionPane.DEFAULT_OPTION,
                    JOptionPane.QUESTION_MESSAGE, null, format, format[0]);
            if (formatResponse != JOptionPane.CLOSED_OPTION) {
                JFileChooser chooser = vista.getFileChooserSalvaFolder();
                File file;//from  w w w  .  ja v a 2 s  . c  om
                int returnVal = chooser.showDialog(WindowManager.getDefault().getMainWindow(),
                        NbBundle.getMessage(Costanti.class, Costanti.EXPORT));
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    file = chooser.getSelectedFile();
                    if (formatResponse == 0) {
                        DAOCsv daoCsv = new DAOCsv();
                        daoCsv.exportPKConstraintCSVinstances(mappingTask, pkTableNames, file.getAbsolutePath(),
                                scenarioNo);
                        DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
                                NbBundle.getMessage(Costanti.class, Costanti.EXPORT_COMPLETED_OK)));
                    } else if (formatResponse == 1) {
                        DAOJson daoJson = new DAOJson();
                        daoJson.exportPKConstraintJsoninstances(mappingTask, pkTableNames,
                                file.getAbsolutePath(), scenarioNo);
                        DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
                                NbBundle.getMessage(Costanti.class, Costanti.EXPORT_COMPLETED_OK)));
                    }
                }
            }
        }
    }
}

From source file:utilities.GraphViewer.java

public void actionPerformed(ActionEvent e) {
    // Evenement button parcourir
    if (e.getSource() == this.parcourir) {

        JFileChooser fileopen = new JFileChooser();
        FiltreSimple filter = new FiltreSimple("Fichier res", "res");
        fileopen.addChoosableFileFilter(filter);
        int ret = fileopen.showDialog(null, "Open file");
        if (ret == JFileChooser.APPROVE_OPTION) {
            File file = fileopen.getSelectedFile();
            System.out.println(file.getPath());
            this.addSensor(file.getPath());

        }/*from   www . j a v  a2  s  .c om*/

    } else {

        JCheckBox check;
        for (int i = 0; i < this.sensors.size(); i++) {
            check = sensors.get(i);
            if (e.getSource() == check) {
                if (check.isSelected()) {
                    if (!this.isExist(check)) {
                        String s = check.getText();
                        s = s.substring(1);
                        ajouterFichier(this.db.getPath(check.getText()));
                        sensors1.addLast(check);
                        this.graphe.revalidate();
                    }

                } else {
                    this.removeSerie(check.getText());
                    sensors1.remove(check);
                    this.graphe.revalidate();

                }
                break;
            }
        }

    }

}

From source file:grafix.telas.TelaComparativos.java

private void salvarJPEG() {
    JFileChooser chooser = new JFileChooser();
    chooser.setSelectedFile(new File(".jpg"));
    int returnVal = chooser.showSaveDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = chooser.getSelectedFile();
        try {/*w  w  w  .  j  av  a2  s.com*/
            ChartUtilities.saveChartAsJPEG(file, chartPanel.getChart(), chartPanel.getWidth(),
                    chartPanel.getHeight());
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}