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:net.aepik.alasca.gui.util.LoadFileFrame.java

/**
 * Perform action on event for this object.
 *///from  w  ww . ja  va  2s .c  o m
public void actionPerformed(ActionEvent e) {
    Object o = e.getSource();
    if (o == boutonOpenFile) {
        JFileChooser jfcProgramme = new JFileChooser(".");
        jfcProgramme.setMultiSelectionEnabled(false);
        jfcProgramme.setDialogTitle("Selectionner un fichier");
        jfcProgramme.setApproveButtonText("Selectionner");
        jfcProgramme.setApproveButtonToolTipText("Cliquer apres avoir selectionn un fichier");
        jfcProgramme.setAcceptAllFileFilterUsed(false);
        if (jfcProgramme.showDialog(this, null) == JFileChooser.APPROVE_OPTION) {
            try {
                filename.setText(jfcProgramme.getSelectedFile().getCanonicalPath());
            } catch (IOException ioe) {
                JOptionPane.showMessageDialog(null, "Erreur de nom de fichier.", "Erreur",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    }
    if (o == boutonOk && filename.getText().length() != 0) {
        if (!this.loadFile(filename.getText(), (String) this.syntaxes.getSelectedItem())) {
            JOptionPane.showMessageDialog(this, this.getErrorMessage(), "Erreur", JOptionPane.ERROR_MESSAGE);
        } else {
            windowClosing(null);
        }
    }
    if (o == boutonAnnuler) {
        windowClosing(null);
    }
}

From source file:org.jax.maanova.plot.SaveChartAction.java

/**
 * {@inheritDoc}//from   ww  w .j a  v  a 2  s  . c om
 */
public void actionPerformed(ActionEvent e) {
    JFreeChart myChart = this.chart;
    Dimension mySize = this.size;

    if (myChart == null || mySize == null) {
        LOG.severe("Failed to save graph image because of a null value");
        MessageDialogUtilities.errorLater(Maanova.getInstance().getApplicationFrame(),
                "Internal error: Failed to save graph image.", "Image Save Failed");
    } else {
        // use the remembered starting dir
        MaanovaApplicationConfigurationManager configurationManager = MaanovaApplicationConfigurationManager
                .getInstance();
        JMaanovaApplicationState applicationState = configurationManager.getApplicationState();
        FileType rememberedJaxbImageDir = applicationState.getRecentImageExportDirectory();
        File rememberedImageDir = null;
        if (rememberedJaxbImageDir != null && rememberedJaxbImageDir.getFileName() != null) {
            rememberedImageDir = new File(rememberedJaxbImageDir.getFileName());
        }

        // select the image file to save
        JFileChooser fileChooser = new JFileChooser(rememberedImageDir);
        fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        fileChooser.setApproveButtonText("Save Graph");
        fileChooser.setDialogTitle("Save Graph as Image");
        fileChooser.setMultiSelectionEnabled(false);
        fileChooser.addChoosableFileFilter(PngFileFilter.getInstance());
        fileChooser.setFileFilter(PngFileFilter.getInstance());
        int response = fileChooser.showSaveDialog(Maanova.getInstance().getApplicationFrame());
        if (response == JFileChooser.APPROVE_OPTION) {
            File selectedFile = fileChooser.getSelectedFile();

            // tack on the extension if there isn't one
            // already
            if (!PngFileFilter.getInstance().accept(selectedFile)) {
                String newFileName = selectedFile.getName() + "." + PngFileFilter.PNG_EXTENSION;
                selectedFile = new File(selectedFile.getParentFile(), newFileName);
            }

            if (selectedFile.exists()) {
                // ask the user if they're sure they want to overwrite
                String message = "Exporting the graph image to " + selectedFile.getAbsolutePath()
                        + " will overwrite an " + " existing file. Would you like to continue anyway?";
                if (LOG.isLoggable(Level.FINE)) {
                    LOG.fine(message);
                }

                boolean overwriteOk = MessageDialogUtilities
                        .confirmOverwrite(Maanova.getInstance().getApplicationFrame(), selectedFile);
                if (!overwriteOk) {
                    if (LOG.isLoggable(Level.FINE)) {
                        LOG.fine("overwrite canceled");
                    }
                    return;
                }
            }

            try {
                ChartUtilities.saveChartAsPNG(selectedFile, myChart, mySize.width, mySize.height);

                File parentDir = selectedFile.getParentFile();
                if (parentDir != null) {
                    // update the "recent image directory"
                    ObjectFactory objectFactory = new ObjectFactory();
                    FileType latestJaxbImageDir = objectFactory.createFileType();
                    latestJaxbImageDir.setFileName(parentDir.getAbsolutePath());
                    applicationState.setRecentImageExportDirectory(latestJaxbImageDir);
                }
            } catch (Exception ex) {
                LOG.log(Level.SEVERE, "failed to save graph image", ex);
            }
        }
    }
}

From source file:modelibra.swing.app.util.FileSelector.java

/**
 * Selects a directory (path).//from  w w  w  .  j  a  v a2s . c o m
 * 
 * @param lang
 *            language
 * @return chosen directory path
 */
public String selectDirectory(NatLang lang) {
    JFileChooser dirChooser = new JFileChooser(lastDirectoryPath);
    dirChooser.setLocale(lang.getLocale());
    dirChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    dirChooser.setToolTipText(lang.getText("selectDirectory"));
    dirChooser.setDialogTitle(lang.getText("selectDirectory"));
    dirChooser.showDialog(null, lang.getText("selectDirectory"));
    File f = dirChooser.getSelectedFile();
    if (f != null) {
        lastDirectoryPath = f.getPath();
        return lastDirectoryPath;
    } else {
        return null;
    }
}

From source file:dylemator.UserList.java

private void exportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportButtonActionPerformed
    if (this.filenameCombo.getSelectedIndex() == 0)
        return;/*w  ww . j  a v a  2s .  c o  m*/
    String sheetName = (String) this.filenameCombo.getSelectedItem();
    Workbook wb = new XSSFWorkbook();
    Sheet sheet = wb.createSheet(sheetName);
    Row headerRow = sheet.createRow(0);
    String[] headers = exportData.get(0);
    int numOfColumns = headers.length;
    for (int i = 0; i < numOfColumns; i++) {
        Cell cell = headerRow.createCell(i);
        cell.setCellValue(headers[i]);
    }

    int rowCount = exportData.size();
    for (int rownum = 1; rownum < rowCount; rownum++) {
        Row row = sheet.createRow(rownum);
        String[] values = exportData.get(rownum);
        for (int i = 0; i < numOfColumns; i++) {
            Cell cell = row.createCell(i);
            cell.setCellValue(values[i]);
        }
    }

    String defaultFilename = "Export.xlsx";
    JFileChooser f = new JFileChooser(System.getProperty("user.dir"));
    f.setSelectedFile(new File(defaultFilename));
    f.setDialogTitle("Wybierz nazw dla pliku eksportu");
    f.setFileSelectionMode(JFileChooser.FILES_ONLY);
    FileFilter ff = new FileFilter() {
        @Override
        public boolean accept(File file) {
            if (file.getName().endsWith(".xlsx"))
                return true;
            return false;
        }

        @Override
        public String getDescription() {
            return "";
        }
    };
    f.setFileFilter(ff);

    File file = null;
    int save = f.showSaveDialog(this);
    if (save == JFileChooser.APPROVE_OPTION)
        file = f.getSelectedFile();
    else
        return;

    FileOutputStream out;
    try {
        out = new FileOutputStream(file);
        wb.write(out);
        out.close();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(UserList.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(UserList.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:org.pgptool.gui.ui.importkey.KeyImporterPm.java

public MultipleFilesChooserDialog getSourceFileChooser() {
    if (sourceFileChooser == null) {
        sourceFileChooser = new MultipleFilesChooserDialog(findRegisteredWindowIfAny(), appProps,
                BROWSE_FOLDER) {//from   ww w .j  a v  a2s. c  o  m
            @Override
            protected void doFileChooserPostConstruct(JFileChooser ofd) {
                super.doFileChooserPostConstruct(ofd);
                ofd.setDialogTitle(Messages.get("action.importKey"));

                ofd.setAcceptAllFileFilterUsed(false);
                ofd.addChoosableFileFilter(keyFilesFilter);
                ofd.addChoosableFileFilter(ofd.getAcceptAllFileFilter());
                ofd.setFileFilter(ofd.getChoosableFileFilters()[0]);
            }

            private FileFilter keyFilesFilter = new FileFilter() {
                @Override
                public boolean accept(File f) {
                    if (f.isDirectory() || !f.isFile()) {
                        return true;
                    }
                    if (!isExtension(f.getName(), EXTENSIONS)) {
                        return false;
                    }

                    // NOTE: Although it gives best results -- I have a
                    // slight concern that this might be too heavy operation
                    // to perform thorough -- check for each file
                    // contents. My hope is that since we're checking only
                    // key files it shouldn't be a problem. Non-key files
                    // with same xtensions will not take a long time to fail
                    try {
                        Key readKey = keyFilesOperations.readKeyFromFile(f.getAbsolutePath());
                        Preconditions.checkState(readKey != null, "Key wasn't parsed");

                        Key existingKey = keyRingService.findKeyById(readKey.getKeyInfo().getKeyId());
                        if (existingKey == null) {
                            return true;
                        }
                        if (!existingKey.getKeyData().isCanBeUsedForDecryption()
                                && readKey.getKeyData().isCanBeUsedForDecryption()) {
                            return true;
                        }
                        return false;
                    } catch (Throwable t) {
                        // in this case it's not an issue. So it's debug
                        // level
                        log.debug(
                                "File is not accepte for file chooser becasue was not able to read it as a key",
                                t);
                    }

                    return false;
                }

                private boolean isExtension(String fileName, String[] extensions) {
                    String extension = FilenameUtils.getExtension(fileName);
                    if (!StringUtils.hasText(extension)) {
                        return false;
                    }

                    for (String ext : extensions) {
                        if (ext.equalsIgnoreCase(extension)) {
                            return true;
                        }
                    }
                    return false;
                }

                @Override
                public String getDescription() {
                    return "Key files (.asc, .bpg)";
                }
            };
        };
    }
    return sourceFileChooser;
}

From source file:TextFileHandler.java

public File openDirectory(String title) {
    File result = null;// www  .java2 s  . c  o  m
    JFileChooser chooser = new JFileChooser(new File("."));
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    if (title != null)
        chooser.setDialogTitle(title);
    int retVal = chooser.showOpenDialog(null);
    if (retVal == JFileChooser.APPROVE_OPTION) {
        result = chooser.getSelectedFile();
    }
    return result;
}

From source file:ca.uhn.hl7v2.testpanel.ui.conn.Hl7ConnectionPanel.java

private static void chooseKeystore(Component theParentController, JTextField theTextbox) {
    String directory = Prefs.getInstance().getInterfaceHohSecurityKeystoreDirectory();
    directory = StringUtils.defaultString(directory, ".");
    JFileChooser chooser = new JFileChooser(directory);
    chooser.setDialogType(JFileChooser.OPEN_DIALOG);
    chooser.setDialogTitle("Select a Java Keystore");
    int result = chooser.showOpenDialog(theParentController);
    if (result == JFileChooser.APPROVE_OPTION) {
        Prefs.getInstance().setInterfaceHohSecurityKeystoreDirectory(chooser.getSelectedFile().getParent());
        theTextbox.setText(chooser.getSelectedFile().getAbsolutePath());
    }/*from  ww  w.ja v a 2s .c o m*/
}

From source file:com.wcmc.Software.excel.ExportCMAPoints.java

@Override
public void run() {

    Date now = new Date();

    SimpleDateFormat date = new SimpleDateFormat("yyyy");

    String year = date.format(now);

    JFileChooser saveAs = new JFileChooser(System.getProperty("user.home"));
    saveAs.setDialogTitle("Save Standings For The " + year + " Season");
    saveAs.setFileFilter(new FileNameExtensionFilter("Excel 2003 (*.xls)", "xls"));
    if (saveAs.showSaveDialog(Client.window) == JFileChooser.APPROVE_OPTION) {
        File exportFile = null;//  w  w  w .  j a  v  a 2  s .  c o m
        if (!saveAs.getSelectedFile().toString().endsWith(".xls")) {
            exportFile = new File(saveAs.getSelectedFile().getAbsolutePath() + ".xls");
        } else {
            exportFile = saveAs.getSelectedFile();
        }

        try {
            WritableWorkbook excelFile = Workbook.createWorkbook(exportFile);
            System.out.println("Exporting Standings...");
            int sheetNumber = 0;
            ArrayList<ClassItem> classes = Client.ms.rS.classes.getClasses();

            Client.ms.trS.prgExport.setVisible(true);
            Client.ms.trS.prgExport.setPercent(0);
            Client.ms.trS.prgClass.setVisible(true);
            Client.ms.trS.prgClass.setPercent(0);
            Client.ms.trS.overall.setVisible(true);
            Client.ms.trS.classSpecific.setVisible(true);
            for (int i = 0; i < classes.size(); i++) {
                ClassItem c = classes.get(i);
                Client.ms.trS.classSpecific.setText("Class: " + c.getText());
                WritableSheet classSheet = excelFile.createSheet(c.getText().toString(), sheetNumber);
                classSheet.mergeCells(1, 1, 13, 1);
                classSheet.addCell(new Label(1, 1,
                        c.getText().toString() + " - Niagara Motorcycle Raceway - " + year + " Season",
                        headerGrey));
                classSheet.addCell(new Label(1, 3, "Plate #", headerBold));
                classSheet.addCell(new Label(2, 3, "CMA", headerBold));
                classSheet.addCell(new Label(3, 3, "First Name", headerBold));
                classSheet.addCell(new Label(4, 3, "Last Name", headerBold));
                classSheet.addCell(new Label(5, 3, "Total Points", headerBold));
                Client.sc.send(CONST.GET_RACE_DATES + " " + year + CONST.seperator + c.getID());
                String jsonData = null;
                while ((jsonData = Client.sc.getInfo()) == null) {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                if (jsonData != null) {

                    JSONParser parse = new JSONParser();
                    JSONObject jsonDates = (JSONObject) parse.parse(jsonData);
                    if (jsonDates != null) {
                        JSONArray jsonDatesArray = (JSONArray) jsonDates.get("dates");
                        JSONArray riderDataArray = (JSONArray) jsonDates.get("riders");
                        if (riderDataArray.size() == 0) {
                            excelFile.removeSheet(sheetNumber);
                            continue;
                        }
                        for (int d = 0; d < jsonDatesArray.size(); d++) {
                            String dateString = (String) jsonDatesArray.get(d);
                            classSheet.mergeCells(6 + (d * 2), 3, 6 + (d * 2) + 1, 3);

                            DateFormat customDateFormat = new DateFormat("MMMM dd");
                            WritableCellFormat dateFormat = new WritableCellFormat(customDateFormat);
                            dateFormat.setBorder(Border.ALL, BorderLineStyle.THICK);
                            dateFormat.setAlignment(Alignment.CENTRE);
                            dateFormat.setFont(arial10bold);
                            SimpleDateFormat dateParser = new SimpleDateFormat("yyyy-M-d");

                            Date eventDate = dateParser.parse(dateString);

                            jxl.write.DateTime dateFormatCell = new jxl.write.DateTime(6 + (d * 2), 3,
                                    eventDate, dateFormat);

                            classSheet.addCell(dateFormatCell);
                            classSheet.addCell(new Label(6 + (d * 2), 5, "POS", dataCenter));
                            classSheet.addCell(new Label(6 + (d * 2) + 1, 5, "Points", dataCenter));
                            classSheet.setColumnView(6 + (d * 2), 10);
                            classSheet.setColumnView(6 + (d * 2) + 1, 10);

                        }

                        classSheet.addCell(new Label(6 + jsonDatesArray.size() * 2, 3, "City", headerBold));
                        classSheet.addCell(new Label(7 + jsonDatesArray.size() * 2, 3, "Sponsors", headerBold));
                        classSheet.setColumnView(6 + jsonDatesArray.size() * 2, 25);
                        classSheet.setColumnView(7 + jsonDatesArray.size() * 2, 75);

                        for (int r = 0; r < riderDataArray.size(); r++) {
                            JSONObject rider = (JSONObject) riderDataArray.get(r);
                            JSONObject bike = (JSONObject) rider.get("bike");
                            if (bike != null) {
                                classSheet.addCell(new Number(1, 6 + r, (long) bike.get("plate"), pointsBold));
                            }
                            classSheet.addCell(new Label(2, 6 + r, (String) rider.get("license"), pointsBold));
                            classSheet
                                    .addCell(new Label(3, 6 + r, (String) rider.get("first_name"), dataCenter));
                            classSheet
                                    .addCell(new Label(4, 6 + r, (String) rider.get("last_name"), dataCenter));
                            classSheet
                                    .addCell(new Number(5, 6 + r, (long) rider.get("totalPoints"), pointsBold));

                            JSONArray events = (JSONArray) rider.get("events");
                            boolean hasEvent = false;
                            for (int d = 0; d < jsonDatesArray.size(); d++) {
                                hasEvent = false;
                                for (int e = 0; e < events.size(); e++) {
                                    String dateString = (String) jsonDatesArray.get(d);
                                    JSONObject event = (JSONObject) events.get(e);
                                    if (event.get("date").equals(dateString)) {
                                        classSheet.addCell(new Number(6 + (d * 2), 6 + r,
                                                (long) event.get("position"), dataCenter));
                                        classSheet.addCell(new Number(6 + (d * 2) + 1, 6 + r,
                                                (long) event.get("points"), dataCenter));
                                        hasEvent = true;
                                    }
                                }
                                if (!hasEvent) {
                                    classSheet.addCell(new Label(6 + (d * 2), 6 + r, "", dataCenter));
                                    classSheet.addCell(new Label(6 + (d * 2) + 1, 6 + r, "", dataCenter));
                                }
                            }
                            classSheet.addCell(new Label(6 + (jsonDatesArray.size() * 2), 6 + r,
                                    (String) rider.get("city"), dataCenter));
                            classSheet.addCell(new Label(7 + (jsonDatesArray.size() * 2), 6 + r,
                                    (String) rider.get("sponsors"), dataWrapped));
                            Client.ms.trS.prgClass
                                    .setPercent(((double) r / (double) riderDataArray.size()) * 100);
                        }
                    }
                }

                // Set Widths
                classSheet.setRowView(3, 300);

                classSheet.setColumnView(1, 10);
                classSheet.setColumnView(2, 10);
                classSheet.setColumnView(3, 18);
                classSheet.setColumnView(4, 18);
                classSheet.setColumnView(5, 15);
                sheetNumber++;

                Client.ms.trS.prgExport
                        .setPercent(((double) i / (double) Client.ms.rS.classes.getClasses().size()) * 100);
            }
            excelFile.write();
            excelFile.close();

            WorkBook sortedWorkbook = new WorkBook();
            try {
                sortedWorkbook.read(new FileInputStream(exportFile));
                for (int i = 0; i < sheetNumber; i++) {
                    sortedWorkbook.setSheet(i);
                    sortedWorkbook.sort(6, 1, 60, 60, true, -5, 0, 0);
                }
                sortedWorkbook.setSheet(0);
                FileOutputStream out = new FileOutputStream(exportFile);
                sortedWorkbook.write(out);
                out.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
            Client.ms.trS.prgExport.setVisible(false);
            Client.ms.trS.prgClass.setVisible(false);
            Client.ms.trS.overall.setVisible(false);
            Client.ms.trS.classSpecific.setVisible(false);
        } catch (IOException | WriteException | ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (java.text.ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

From source file:net.lldp.checksims.ui.results.ScrollViewer.java

/**
 * Create a scroll viewer from a sortable Matrix Viewer
 * @param results the sortableMatrix to view
 * @param toRevalidate frame to revalidate sometimes
 *///from w ww. ja  v  a  2 s  . c o  m
public ScrollViewer(SimilarityMatrix exportMatrix, SortableMatrixViewer results, JFrame toRevalidate) {
    resultsView = new JScrollPane(results);
    setBackground(Color.black);
    resultsView.addComponentListener(new ComponentListener() {

        @Override
        public void componentHidden(ComponentEvent arg0) {
        }

        @Override
        public void componentMoved(ComponentEvent arg0) {
        }

        @Override
        public void componentResized(ComponentEvent ce) {
            Dimension size = ce.getComponent().getSize();
            results.padToSize(size);
        }

        @Override
        public void componentShown(ComponentEvent arg0) {
        }
    });

    resultsView.getViewport().addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            Rectangle r = resultsView.getViewport().getViewRect();
            results.setViewAt(r);
        }
    });

    resultsView.setBackground(Color.black);
    sidebar = new JPanel();

    setPreferredSize(new Dimension(900, 631));
    setMinimumSize(new Dimension(900, 631));
    sidebar.setPreferredSize(new Dimension(200, 631));
    sidebar.setMaximumSize(new Dimension(200, 3000));
    resultsView.setMinimumSize(new Dimension(700, 631));
    resultsView.setPreferredSize(new Dimension(700, 631));

    sidebar.setBackground(Color.GRAY);

    setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));

    this.add(sidebar);
    this.add(resultsView);

    resultsView.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    resultsView.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    resultsView.getVerticalScrollBar().setUnitIncrement(16);
    resultsView.getHorizontalScrollBar().setUnitIncrement(16);

    Integer[] presetThresholds = { 80, 60, 40, 20, 0 };
    JComboBox<Integer> threshHold = new JComboBox<Integer>(presetThresholds);
    threshHold.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent event) {
            if (event.getStateChange() == ItemEvent.SELECTED) {
                Integer item = (Integer) event.getItem();
                results.updateThreshold(item / 100.0);
                toRevalidate.revalidate();
                toRevalidate.repaint();
            }
        }
    });
    threshHold.setSelectedIndex(0);
    results.updateThreshold((Integer) threshHold.getSelectedItem() / 100.0);

    JTextField student1 = new JTextField(15);
    JTextField student2 = new JTextField(15);

    KeyListener search = new KeyListener() {

        @Override
        public void keyPressed(KeyEvent e) {
        }

        @Override
        public void keyReleased(KeyEvent e) {
            results.highlightMatching(student1.getText(), student2.getText());
            toRevalidate.revalidate();
            toRevalidate.repaint();
        }

        @Override
        public void keyTyped(KeyEvent e) {
        }
    };

    student1.addKeyListener(search);
    student2.addKeyListener(search);

    Collection<MatrixPrinter> printerNameSet = MatrixPrinterRegistry.getInstance()
            .getSupportedImplementations();
    JComboBox<MatrixPrinter> exportAs = new JComboBox<>(new Vector<>(printerNameSet));
    JButton exportAsSave = new JButton("Save");

    JFileChooser fc = new JFileChooser();

    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setCurrentDirectory(new java.io.File("."));
    fc.setDialogTitle("Save results");

    exportAsSave.addActionListener(ae -> {
        MatrixPrinter method = (MatrixPrinter) exportAs.getSelectedItem();

        int err = fc.showDialog(toRevalidate, "Save");
        if (err == JFileChooser.APPROVE_OPTION) {
            try {
                FileUtils.writeStringToFile(fc.getSelectedFile(), method.printMatrix(exportMatrix));
            } catch (InternalAlgorithmError | IOException e1) {
                // TODO log / show error
            }
        }
    });

    JPanel thresholdLabel = new JPanel();
    JPanel studentSearchLabel = new JPanel();
    JPanel fileOutputLabel = new JPanel();

    thresholdLabel.setBorder(BorderFactory.createTitledBorder("Matching Threshold"));
    studentSearchLabel.setBorder(BorderFactory.createTitledBorder("Student Search"));
    fileOutputLabel.setBorder(BorderFactory.createTitledBorder("Save Results"));

    thresholdLabel.add(threshHold);
    studentSearchLabel.add(student1);
    studentSearchLabel.add(student2);
    fileOutputLabel.add(exportAs);
    fileOutputLabel.add(exportAsSave);

    studentSearchLabel.setPreferredSize(new Dimension(200, 100));
    studentSearchLabel.setMinimumSize(new Dimension(200, 100));
    thresholdLabel.setPreferredSize(new Dimension(200, 100));
    thresholdLabel.setMinimumSize(new Dimension(200, 100));
    fileOutputLabel.setPreferredSize(new Dimension(200, 100));
    fileOutputLabel.setMinimumSize(new Dimension(200, 100));

    sidebar.setMaximumSize(new Dimension(200, 4000));

    sidebar.add(thresholdLabel);
    sidebar.add(studentSearchLabel);
    sidebar.add(fileOutputLabel);
}

From source file:net.sf.keystore_explorer.gui.dialogs.DViewCertCsrPem.java

private void exportPressed() {
    File chosenFile = null;/*from w w  w  . j av  a  2s  .co  m*/
    FileWriter fw = null;

    String title;
    if (cert != null) {
        title = res.getString("DViewCertCsrPem.ExportPemCertificate.Title");
    } else {
        title = res.getString("DViewCertCsrPem.ExportPemCsr.Title");
    }
    try {
        String certPem = jtaPem.getText();

        JFileChooser chooser = FileChooserFactory.getX509FileChooser();
        chooser.setCurrentDirectory(CurrentDirectory.get());
        chooser.setDialogTitle(title);
        chooser.setMultiSelectionEnabled(false);

        int rtnValue = JavaFXFileChooser.isFxAvailable() ? chooser.showSaveDialog(this)
                : chooser.showDialog(this, res.getString("DViewCertCsrPem.ChooseExportFile.button"));

        if (rtnValue != JFileChooser.APPROVE_OPTION) {
            return;
        }

        chosenFile = chooser.getSelectedFile();
        CurrentDirectory.updateForFile(chosenFile);

        if (chosenFile.isFile()) {
            String message = MessageFormat.format(res.getString("DViewCertCsrPem.OverWriteFile.message"),
                    chosenFile);

            int selected = JOptionPane.showConfirmDialog(this, message, title, JOptionPane.YES_NO_OPTION);
            if (selected != JOptionPane.YES_OPTION) {
                return;
            }
        }

        fw = new FileWriter(chosenFile);
        fw.write(certPem);
    } catch (FileNotFoundException ex) {
        JOptionPane.showMessageDialog(this,
                MessageFormat.format(res.getString("DViewCertCsrPem.NoWriteFile.message"), chosenFile), title,
                JOptionPane.WARNING_MESSAGE);
        return;
    } catch (Exception ex) {
        DError.displayError(this, ex);
        return;
    } finally {
        IOUtils.closeQuietly(fw);
    }

    JOptionPane.showMessageDialog(this, res.getString("DViewCertCsrPem.ExportPemCertificateSuccessful.message"),
            title, JOptionPane.INFORMATION_MESSAGE);
}