Example usage for javax.swing JFileChooser setDialogTitle

List of usage examples for javax.swing JFileChooser setDialogTitle

Introduction

In this page you can find the example usage for javax.swing JFileChooser setDialogTitle.

Prototype

@BeanProperty(preferred = true, description = "The title of the JFileChooser dialog window.")
public void setDialogTitle(String dialogTitle) 

Source Link

Document

Sets the string that goes in the JFileChooser window's title bar.

Usage

From source file:ro.nextreports.designer.action.report.ViewReportSqlAction.java

public void actionPerformed(ActionEvent e) {

    JFileChooser fc = new JFileChooser();
    fc.setDialogTitle(I18NSupport.getString("select.next.reports.file"));
    fc.setAcceptAllFileFilterUsed(false);
    fc.addChoosableFileFilter(new NextFileFilter());
    int returnVal = fc.showOpenDialog(Globals.getMainFrame());
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File f = fc.getSelectedFile();
        if (f != null) {

            String sql = null;/*from   w ww  .  j a v a 2 s  .  com*/
            String entityName = null;
            Object entity = null;
            FileInputStream fis = null;
            entityName = f.getName();
            try {
                XStream xstream = XStreamFactory.createXStream();
                fis = new FileInputStream(f);
                entity = xstream.fromXML(fis);

            } catch (Exception ex) {
                Show.error(ex);
            } finally {
                if (fis != null) {
                    try {
                        fis.close();
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                }
            }

            if (entityName.endsWith(QueryFilter.QUERY_EXTENSION)
                    || entityName.endsWith(ReportFilter.REPORT_EXTENSION)) {

                Report report = (Report) entity;
                if (report.getSql() != null) {
                    sql = report.getSql();
                } else if (report.getQuery() != null) {
                    SelectQuery query = report.getQuery();
                    try {
                        query.setDialect(DialectUtil.getDialect(Globals.getConnection()));
                    } catch (Exception ex) {
                        ex.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
                        LOG.error(ex.getMessage(), ex);
                    }
                    sql = query.toString();
                }

            } else if (entityName.endsWith(ChartFilter.CHART_EXTENSION)) {
                Chart chart = (Chart) entity;
                if (chart.getReport().getSql() != null) {
                    sql = chart.getReport().getSql();
                } else if (chart.getReport().getQuery() != null) {
                    SelectQuery query = chart.getReport().getQuery();
                    try {
                        query.setDialect(DialectUtil.getDialect(Globals.getConnection()));
                    } catch (Exception ex) {
                        ex.printStackTrace();
                        LOG.error(ex.getMessage(), ex);
                    }
                    sql = query.toString();
                }
            }

            Editor editor = new Editor();
            editor.setText(sql);
            editor.setPreferredSize(new Dimension(400, 400));
            JFrame frame = new JFrame(I18NSupport.getString("view.sql.info", entityName));
            frame.setIconImage(ImageUtil.getImageIcon("report_view").getImage());
            frame.setLayout(new GridBagLayout());
            frame.add(editor, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER,
                    GridBagConstraints.BOTH, new Insets(10, 10, 10, 10), 0, 0));
            frame.pack();
            Show.centrateComponent(Globals.getMainFrame(), frame);
            frame.setVisible(true);

        }
    }

}

From source file:ro.nextreports.designer.wizimport.ImportPathSelectionWizardPanel.java

private void init() {
    setLayout(new BorderLayout());

    nameTextField = new JTextField();
    nameTextField.setPreferredSize(dim);
    nameTextField.setEditable(false);/*  w  w w  .  java 2s.  c om*/

    propCheck = new JCheckBox(I18NSupport.getString("wizard.import.panel.start.select.title.prop"), true);

    selButton = new JButton();
    selButton.setPreferredSize(buttonDim);
    selButton.setMaximumSize(buttonDim);
    selButton.setMinimumSize(buttonDim);
    selButton.setIcon(ImageUtil.getImageIcon("folder"));
    selButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser fc = new JFileChooser();
            fc.setDialogTitle(I18NSupport.getString("import.long.desc"));
            fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int returnVal = fc.showSaveDialog((JDialog) context.getAttribute(ImportWizard.MAIN_FRAME));

            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File f = fc.getSelectedFile();
                if (f != null) {
                    nameTextField.setText(f.getName());
                    path = f.getAbsolutePath();
                }
            }
        }
    });

    JPanel dsPanel = new JPanel(new GridBagLayout());
    dsPanel.add(new JLabel(I18NSupport.getString("wizard.import.panel.start.select.title.label")),
            new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
                    new Insets(5, 5, 5, 0), 0, 0));
    dsPanel.add(nameTextField, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
            GridBagConstraints.NONE, new Insets(5, 5, 5, 0), 0, 0));
    dsPanel.add(selButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
            GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
    dsPanel.add(propCheck, new GridBagConstraints(0, 1, 3, 1, 0.0, 0.0, GridBagConstraints.WEST,
            GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
    dsPanel.add(new JLabel(""), new GridBagConstraints(3, 1, 1, 2, 1.0, 1.0, GridBagConstraints.WEST,
            GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
    add(dsPanel, BorderLayout.CENTER);
}

From source file:sc.fiji.kappa.gui.CurvesExporter.java

public void export(boolean exportAveragePerCurve) throws IOException {

    JFileChooser kappaExport = new JFileChooser();

    String dirPath = frame.getImageStack().getOriginalFileInfo().directory;
    if (dirPath != null) {
        String kappaPath = FilenameUtils.removeExtension(frame.getImageStack().getOriginalFileInfo().fileName);
        kappaPath += ".csv";
        File fullPath = new File(dirPath, kappaPath);
        kappaExport.setSelectedFile(fullPath);
    }//www  .j a v  a  2s .  c o  m

    kappaExport.setFileFilter(new FileNameExtensionFilter("CSV File", "csv"));
    kappaExport.setDialogTitle("Export Curve Data");

    // Handles export button action.
    int returnVal = kappaExport.showSaveDialog(frame);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = kappaExport.getSelectedFile();
        exportToFile(file, exportAveragePerCurve);
    }
}

From source file:se.cambio.cds.gdl.editor.controller.GDLEditor.java

public void saveCompiledGuideAsObject(byte[] compiledGuide, Guide guide) {
    GDLEditor controller = EditorManager.getActiveGDLEditor();
    String idGuide = controller.getIdGuide();
    if (idGuide == null) {
        idGuide = GDLEditorLanguageManager.getMessage("Guide");
    }/*from  w  w w  . j  a v a 2  s  .co  m*/
    if (compiledGuide != null) {
        try {
            String guideSource = controller.serializeCurrentGuide();
            if (guideSource != null) {
                JFileChooser fileChooser = new JFileChooser();
                FileNameExtensionFilter filter = new FileNameExtensionFilter(
                        GDLEditorLanguageManager.getMessage("Guide"), new String[] { "guide" });
                fileChooser.setDialogTitle(GDLEditorLanguageManager.getMessage("SaveGuideAsObjectSD"));
                fileChooser.setFileFilter(filter);
                File file = new File(
                        fileChooser.getFileSystemView().getDefaultDirectory() + "/" + idGuide + ".guide");
                fileChooser.setSelectedFile(file);
                int result = fileChooser.showSaveDialog(EditorManager.getActiveEditorWindow());
                File guideFile = fileChooser.getSelectedFile();
                if (result != JFileChooser.CANCEL_OPTION) {
                    idGuide = guideFile.getName();
                    if (idGuide.endsWith(".guide")) {
                        idGuide = idGuide.substring(0, idGuide.length() - 6);
                    }
                    GuideDTO guideDTO = new GuideDTO(idGuide, guideSource, IOUtils.getBytes(guide),
                            compiledGuide, true, Calendar.getInstance().getTime());
                    ObjectOutputStream output = new ObjectOutputStream(
                            new BufferedOutputStream(new FileOutputStream(guideFile)));
                    try {
                        output.writeObject(guideDTO);
                    } catch (Exception e) {
                        ExceptionHandler.handle(e);
                    } finally {
                        output.close();
                    }
                }
            }
        } catch (Exception e) {
            ExceptionHandler.handle(e);
        }
    }
}

From source file:se.cambio.cds.util.ExportUtils.java

public static void exportToHTML(Window owner, Guide guide, String lang) {
    JFileChooser fileChooser = new JFileChooser();
    FileNameExtensionFilter filter = new FileNameExtensionFilter("HTML", new String[] { "html" });
    fileChooser.setDialogTitle(OpenEHRLanguageManager.getMessage("ExportToHTML"));
    fileChooser.setFileFilter(filter);//from  www  .  j  av  a 2 s . c o m
    File selectedFile = new File(guide.getId() + ".html");
    fileChooser.setSelectedFile(selectedFile);
    int result = fileChooser.showSaveDialog(owner);
    if (result != JFileChooser.CANCEL_OPTION) {
        try {
            selectedFile = fileChooser.getSelectedFile();
            FileWriter fstream = new FileWriter(selectedFile);
            BufferedWriter out = new BufferedWriter(fstream);
            out.write(convertToHTML(guide, lang));
            out.close();
        } catch (IOException e) {
            ExceptionHandler.handle(e);
        } catch (InternalErrorException e) {
            ExceptionHandler.handle(e);
        }
    }
}

From source file:secureemailclient.applet.ViewMailFrame.java

private void jButtonVerifyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonVerifyActionPerformed
    String body = jTextAreaBody.getText();
    BufferedReader reader = new BufferedReader(new StringReader(body));
    List<String> lines = new ArrayList<>();
    try {/*ww  w  .ja va  2  s. c  o m*/
        String line;
        do {
            line = reader.readLine();
            if (line != null) {
                lines.add(line);
            }
        } while (line != null);
    } catch (IOException e) {
        e.printStackTrace();
    }

    // check the last three lines
    String[] signature = new String[3];
    if (lines.size() < 3) {
        signature = null;
    } else {
        for (int i = 0; i < 3; ++i) {
            signature[i] = lines.get(lines.size() - 3 + i);
        }
    }

    if (signature == null || !signature[0].equalsIgnoreCase("//DIGITAL SIGNATURE//")) {
        JOptionPane.showMessageDialog(rootPane, "The body message is not signed!");
        return;
    }

    // construct body without signature
    String bodyWithoutSignature = body.substring(0, body.indexOf("\n//DIGITAL SIGNATURE//"));

    PairRS rs = new PairRS(new BigInteger(signature[1], 16), new BigInteger(signature[2], 16));

    PublicKey pk;
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle("Select Public Key");
    int returnVal = chooser.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        String path = chooser.getSelectedFile().getAbsolutePath();
        pk = new PublicKey(path);
    } else {
        return;
    }

    try {
        boolean verified = ECC.verify(bodyWithoutSignature, pk, rs);
        if (verified) {
            JOptionPane.showMessageDialog(rootPane, "The message is verified!");
        } else {
            JOptionPane.showMessageDialog(rootPane, "The message is not valid or the public key is incorrect!");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:smlm.util.SRutil.java

public static String[][] getFiles(String title, String initialRoot, String initialFile) {
    if (title == null || title == "")
        title = "Choose files";
    if (initialRoot == null || initialRoot == "")
        initialRoot = "E:\\Data";

    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    FileNameExtensionFilter filter = new FileNameExtensionFilter("Tiff files", "tif", "tiff");
    chooser.setFileFilter(filter);//from www . j a  v  a 2 s  .  com
    chooser.setDialogTitle(title);
    chooser.setCurrentDirectory(new File(initialRoot));
    chooser.setMultiSelectionEnabled(true);

    int returnVal = chooser.showOpenDialog(null);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        String[][] files = new String[chooser.getSelectedFiles().length][2];
        for (int i = 0; i < files.length; i++) {
            files[i][0] = chooser.getSelectedFiles()[i].getParent();
            files[i][1] = chooser.getSelectedFiles()[i].getName();
        }
        return files;
    } else
        return null;
}

From source file:sms.ViewResults.java

private void itextPrint() {
    //  String searchQuery = "SELECT * FROM `exam` WHERE `yearid` ='" + yearid + "'AND `termid`='"+termid+"'AND `examid`='"+yearid+"'"
    //          + "AND CONCAT(`class`) LIKE '%" + stream + "%'AND YEAR(updated_at)='"+yearchooser.getYear()+"'";

    methods nn = new methods();
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new java.io.File(","));
    chooser.setDialogTitle("Save at");
    chooser.setApproveButtonText("save");
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        try {//  w  w  w . j av a2  s. com
            Form1Exams n = new Form1Exams();
            Document pdfp = new Document();
            PdfWriter.getInstance(pdfp,
                    new FileOutputStream(new File(chooser.getSelectedFile(), "report.pdf")));
            pdfp.open();
            Paragraph p = new Paragraph();
            p.setAlignment(Element.ALIGN_CENTER);
            p.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD));
            Paragraph po = new Paragraph();
            po.setAlignment(Element.ALIGN_CENTER);
            po.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD, 16, Font.BOLD));

            Paragraph pd = new Paragraph();
            pd.setAlignment(Element.ALIGN_CENTER);
            pd.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD, 14, Font.BOLD));
            p.add("ITHANGA SECONDARY SCHOOL");
            po.add("PO.BOX 238  ITHANGA THIKA");
            pd.add(new Date().toString());
            pdfp.add(p);
            pdfp.add(po);
            pdfp.add(pd);

            pdfp.add(new Paragraph("\n.................................................................."
                    + ".................................................................................\n"));
            String[] names = n.findSubjectname();
            PdfPTable tbl = new PdfPTable(names.length + 6);
            tbl.setWidths(new float[] { 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 });
            // tbl.setWidthPercentage(100);
            tbl.setTotalWidth(575);
            tbl.setLockedWidth(true);
            PdfPTable tbl1 = new PdfPTable(names.length + 6);
            tbl1.setWidths(new float[] { 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 });
            // tbl.setWidthPercentage(100);
            tbl1.setTotalWidth(575);
            tbl1.setLockedWidth(true);
            PdfPCell cell = new PdfPCell(new Paragraph("RESULTS"));
            cell.setColspan((names.length + 4) * 2);
            cell.setBackgroundColor(Color.CYAN);
            tbl1.addCell(cell);
            tbl1.addCell("Pos");
            tbl1.addCell("id");
            tbl1.addCell("Name");
            int a;

            for (a = 0; a < names.length; a++) {
                String s = names[a];
                tbl1.addCell(s.substring(0, Math.min(s.length(), 3)));
            }

            tbl1.addCell("Tot");
            tbl1.addCell("Ave");
            tbl1.addCell("Agg");
            pdfp.add(tbl1);

            try {

                String[] Subjects = n.findSubjectid();
                String[] Subjectsnames = n.findSubjectname();
                int subjectCount = Subjects.length;
                ArrayList<ExamDbDataHolder> users = ListUsers(this.sid.getText());

                for (int i = 0; i < users.size(); i++) {
                    tbl.addCell(String.valueOf(i + 1));
                    String id = ((ExamDbDataHolder) users.get(i)).getSid();
                    String nam = nn.getStudentName(id);
                    String name = "Eric";
                    tbl.addCell(id);
                    tbl.addCell(nam);
                    int c = 2;
                    for (int s = 0; s < Subjects.length; s++) {

                        if (Subjects[s].equals("s1")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getMathematics());
                            //  JOptionPane.showMessageDialog(null,((ExamDbDataHolder)users.get(i)).getMathematics());
                            // String maths = ((ExamDbDataHolder)users.get(i)).getMathematics();
                            c++;
                        } else if (Subjects[s].equals("s2")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getEnglish());
                            //row[c] = ((ExamDbDataHolder)users.get(i)).getEnglish();
                            c++;
                        } else if (Subjects[s].equals("s3")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getKiswahili());
                            // row[c] = ((ExamDbDataHolder)users.get(i)).getKiswahili();
                            c++;
                        } else if (Subjects[s].equals("s4")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getPhysics());
                            //   row[c] = ((ExamDbDataHolder)users.get(i)).getPhysics();
                            c++;
                        } else if (Subjects[s].equals("s5")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getChemistry());
                            // row[c] = ((ExamDbDataHolder)users.get(i)).getChemistry();
                            c++;
                        } else if (Subjects[s].equals("s6")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getBiology());
                            //   row[c] = ((ExamDbDataHolder)users.get(i)).getBiology();
                            c++;
                        } else if (Subjects[s].equals("s7")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getHistory());
                            //  row[c] = ((ExamDbDataHolder)users.get(i)).getHistory();
                            c++;
                        } else if (Subjects[s].equals("s8")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getGeography());
                            // row[c] = ((ExamDbDataHolder)users.get(i)).getGeography();
                            c++;
                        } else if (Subjects[s].equals("s9")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getCre());
                            //  row[c] = ((ExamDbDataHolder)users.get(i)).getCre();
                            c++;
                        } else if (Subjects[s].equals("s10")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getIre());
                            //   row[c] = ((ExamDbDataHolder)users.get(i)).getIre();
                            c++;
                        } else if (Subjects[s].equals("s11")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getHre());
                            //   row[c] = ((ExamDbDataHolder)users.get(i)).getHre();
                            c++;
                        } else if (Subjects[s].equals("s12")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getAgriculture());
                            //   row[c] = ((ExamDbDataHolder)users.get(i)).getAgriculture();
                            c++;
                        } else if (Subjects[s].equals("s13")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getHomescience());
                            //  row[c] = ((ExamDbDataHolder)users.get(i)).getHomescience();
                            c++;
                        } else if (Subjects[s].equals("s14")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getArtdesign());
                            //   row[c] = ((ExamDbDataHolder)users.get(i)).getArtdesign();
                            c++;
                        } else if (Subjects[s].equals("s15")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getComputer());
                            // row[c] = ((ExamDbDataHolder)users.get(i)).getComputer();
                            c++;

                        } else if (Subjects[s].equals("s16")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getBuilding());
                            // row[c] = ((ExamDbDataHolder)users.get(i)).getBuilding();
                            c++;
                        } else if (Subjects[s].equals("s17")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getWoodwork());
                            //  row[c] = ((ExamDbDataHolder)users.get(i)).getWoodwork();
                            c++;
                        } else if (Subjects[s].equals("s18")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getMetalwork());
                            //  row[c] = ((ExamDbDataHolder)users.get(i)).getMetalwork();
                            c++;
                        } else if (Subjects[s].equals("s19")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getMusic());
                            //   row[c] = ((ExamDbDataHolder)users.get(i)).getMusic();
                            c++;
                        } else if (Subjects[s].equals("s20")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getFrench());
                            // row[c] = ((ExamDbDataHolder)users.get(i)).getFrench();
                            c++;
                        } else if (Subjects[s].equals("s21")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getGerman());
                            //  row[c] = ((ExamDbDataHolder)users.get(i)).getGerman();
                            c++;
                        } else if (Subjects[s].equals("s22")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getArabic());
                            // row[c] = ((ExamDbDataHolder)users.get(i)).getArabic();
                            c++;
                        } else if (Subjects[s].equals("s23")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getBusiness());
                            //  row[c] = ((ExamDbDataHolder)users.get(i)).getBusiness();
                            c++;
                        }

                    }

                    int tt = ((ExamDbDataHolder) users.get(i)).getTotal();
                    tbl.addCell(String.valueOf(tt));
                    float g = Float.valueOf(tt) / 11;
                    tbl.addCell(String.format("%.1f", g));
                    String gr = nn.checkGrade(yearid, String.format("%.1f", g));
                    tbl.addCell(gr);

                }
                pdfp.add(tbl);
            } catch (Exception j) {
                j.printStackTrace();
            }

            pdfp.close();

            // Image img=new Image.getInstance("j.png");

        } catch (DocumentException ex) {
            Logger.getLogger(ViewResults.class.getName()).log(Level.SEVERE, null, ex);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(ViewResults.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

From source file:su.fmi.photoshareclient.ui.PhotoViewDialog.java

private void SaveImageButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_SaveImageButtonMouseClicked
    JFileChooser fileChooser = new JFileChooser() {
        // A warning for overweiting existing files
        @Override//from   w  w w  .j  ava 2  s  .c  om
        public void approveSelection() {
            File f = getSelectedFile();
            if (f.exists() && getDialogType() == SAVE_DIALOG) {
                int result = JOptionPane.showConfirmDialog(this, "The file exists, overwrite?", "Existing file",
                        JOptionPane.YES_NO_CANCEL_OPTION);
                switch (result) {
                case JOptionPane.YES_OPTION:
                    super.approveSelection();
                    return;
                case JOptionPane.NO_OPTION:
                    return;
                case JOptionPane.CLOSED_OPTION:
                    return;
                case JOptionPane.CANCEL_OPTION:
                    cancelSelection();
                    return;
                }
            }
            super.approveSelection();
        }
    };
    fileChooser.setDialogTitle("Save image as...");
    File rootVolume = File.listRoots()[0];
    fileChooser.setSelectedFile(new File(rootVolume.getAbsolutePath(), this.imageLabel.getFileName()));

    int userSelection = fileChooser.showSaveDialog(this);

    if (userSelection == JFileChooser.APPROVE_OPTION) {
        try {
            File fileToSave = fileChooser.getSelectedFile();
            BufferedImage bi = (BufferedImage) this.imageLabel.getImage();
            String ext = FilenameUtils.getExtension(fileToSave.getAbsolutePath());
            ImageIO.write(bi, ext, fileToSave);
        } catch (IOException ex) {
            Logger.getLogger(PhotoViewDialog.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:tax.MainForm.java

private void printMonthActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_printMonthActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle(" ");
    chooser.setDialogType(JFileChooser.SAVE_DIALOG);
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int returnVal = chooser.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        String folderName = chooser.getSelectedFile().getAbsolutePath();
        //            System.out.println(folderName);

        try {/*ww  w  .j ava 2s.  c o  m*/
            FileUtils.forceMkdir(new File(folderName + "/" + curYear + "/pdf"));
            Printer.createPdf(
                    folderName + "/" + curYear + "/pdf/" + curMonth + ". " + Util.months[curMonth - 1] + ".pdf",
                    curTable);
        } catch (IOException ex) {
            Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
        } catch (DocumentException ex) {
            Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
        }

        new Completed("<html> ? ?<br> .</html>")
                .setVisible(true);
    }
}