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:org.fhaes.fhsamplesize.view.FHSampleSize.java

/**
 * Show open file dialog so the user may choose a file to edit.
 * /* w w  w. j  a  va  2 s.  c  o m*/
 * @return the chosen file if okay was pressed, null if cancel was pressed
 */
private File loadFromOpenFileDialog() {

    String lastVisitedFolder = App.prefs.getPref(PrefKey.PREF_LAST_READ_FOLDER, null);
    JFileChooser fc;

    if (lastVisitedFolder != null)
        fc = new JFileChooser(lastVisitedFolder);
    else
        fc = new JFileChooser();

    fc.setDialogTitle("Select a FHX2 file for sample size analysis");
    fc.setFileFilter(new FHXFileFilter());
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setMultiSelectionEnabled(true);

    int returnVal = fc.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        App.prefs.setPref(PrefKey.PREF_LAST_READ_FOLDER, fc.getSelectedFile().getPath());
        return fc.getSelectedFile();
    }
    return null;
}

From source file:net.panthema.BispanningGame.GamePanel.java

public void writeGraphML() throws IOException {

    // Query user for filename
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle("Specify GraphML file to save");
    chooser.setCurrentDirectory(new File("."));
    FileNameExtensionFilter filter = new FileNameExtensionFilter("GraphML File", "graphml");
    chooser.setFileFilter(filter);/*  w  w  w .j  a v a 2s . co m*/

    if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION)
        return;

    File outfile = chooser.getSelectedFile();
    if (!outfile.getAbsolutePath().endsWith(".graphml")) {
        outfile = new File(outfile.getAbsolutePath() + ".graphml");
    }

    // construct graphml writer
    GraphMLWriter<Integer, MyEdge> graphWriter = new GraphMLWriter<Integer, MyEdge>();

    PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(outfile)));

    graphWriter.addVertexData("x", null, "0", new Transformer<Integer, String>() {
        public String transform(Integer v) {
            return Double.toString(mLayout.getX(v));
        }
    });

    graphWriter.addVertexData("y", null, "0", new Transformer<Integer, String>() {
        public String transform(Integer v) {
            return Double.toString(mLayout.getY(v));
        }
    });

    graphWriter.addEdgeData("color", null, "0", new Transformer<MyEdge, String>() {
        public String transform(MyEdge e) {
            return Integer.toString(e.color);
        }
    });

    graphWriter.save(mGraph, out);
}

From source file:net.panthema.BispanningGame.GamePanel.java

public void writePdf() throws FileNotFoundException, DocumentException {

    // Query user for filename
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle("Specify PDF file to save");
    chooser.setCurrentDirectory(new File("."));
    FileNameExtensionFilter filter = new FileNameExtensionFilter("PDF Documents", "pdf");
    chooser.setFileFilter(filter);//  ww  w  .j a  v  a  2s  .  co  m

    if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION)
        return;

    File outfile = chooser.getSelectedFile();
    if (!outfile.getAbsolutePath().endsWith(".pdf")) {
        outfile = new File(outfile.getAbsolutePath() + ".pdf");
    }

    // Calculate page size rectangle
    Dimension size = mVV.getSize();
    Rectangle rsize = new Rectangle(size.width, size.height);

    // Open the PDF file for writing - and create a Graphics2D object
    Document document = new Document(rsize);
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outfile));
    document.open();

    PdfContentByte contentByte = writer.getDirectContent();
    PdfGraphics2D graphics2d = new PdfGraphics2D(contentByte, size.width, size.height, new DefaultFontMapper());

    // Create a container to hold the visualization
    Container container = new Container();
    container.addNotify();
    container.add(mVV);
    container.setVisible(true);
    container.paintComponents(graphics2d);

    // Dispose of the graphics and close the document
    graphics2d.dispose();
    document.close();

    // Put mVV back onto visible plane
    setLayout(new BorderLayout());
    add(mVV, BorderLayout.CENTER);
}

From source file:IHM.FenetrePrincipale.java

private void btnPhotoArticleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPhotoArticleActionPerformed
    JFileChooser chooser = new JFileChooser(new File(".")); // on fait selectionner a l'utilsateur le fichier voulie

    chooser.setDialogTitle("ouvrir une image");

    int reponse = chooser.showOpenDialog(this);

    if (reponse == JFileChooser.APPROVE_OPTION) {

        InputStream input = null;

        f = chooser.getSelectedFile(); // on rcupre le fichir

        nomPhoto = f.getName(); // on rcupre le nom de fichier
        nomF = f.getAbsolutePath(); // on rcupere le chemin absolue du ficheir

        txtNomPhotoA.setText(nomPhoto);//from ww  w. j  a v a  2s.  co m

    }
}

From source file:com.gele.tools.wow.wdbearmanager.WDBearManager.java

public void actionPerformed(ActionEvent arg0) {
    JMenuItem source = (JMenuItem) (arg0.getSource());

    if (source.getText().equals(MENU_ABOUT)) {
        JOptionPane.showMessageDialog(this, WDBearManager.VERSION_INFO + "\n" + "by kizura\n"
                + WDBearManager.EMAIL + "\n\n" + "\n" + "Supports any WDB version\n" + "\n" + "Thanks to:\n"
                + "DarkMan for testing,\n" + "John for the 1.10 specs, Annunaki for helping with the header,\n"
                + "Andrikos for the 1.6.x WDB specs, Pyro's WDBViewer, WDDG Forum,\n"
                + "blizzhackers, etc etc\n\n" + "This program uses: \n"
                + "JGoodies from http://www.jgoodies.com/\n" + "Hypersonic SQL database 1.7.3\n"
                + "Apache Log4J, Xerces\n" + "Jakarta Commons Logging and CLI\n" + "Castor from ExoLab\n"
                + "MySQL JDBC connector 3.1.7\n" + "HTTPUNIT from Russell Gold\n" + "Jython 2.1\n"
                + "Refer to directory 'licenses' for more details about the software used\n" + "PLEASE:\n"
                + "If you like this program and find it usefull:\n"
                + "Please donate money to a charity oranization of your choice.\n"
                + "I recommend any organization that fights cancer.\n\n" + "License:\n"
                + "WDBearMgr is placed under the GNU GPL. \n" + "For further information, see the page :\n"
                + "http://www.gnu.org/copyleft/gpl.html.\n" + "See licenses/GPL_license.html\n" + "\n"
                + "For a different license please contact the author.", "Info " + VERSION_INFO,
                JOptionPane.INFORMATION_MESSAGE);
        return;//from  ww  w  .  ja  va  2 s.  co  m
    } else if (source.getText().equals(MENU_HELP)) {
        JFrame myFrame = new JFrame("doc/html/index.html");
        //myFrame.setFont(   );
        URL urlHTML = null;
        try {
            JEditorPane htmlPane = new JEditorPane();
            //htmlPane.setFont(sourceFont);
            // .out.println("/scripts/"+source.getName()+".py");
            File scriptFile = new File("doc/html/index.html");
            urlHTML = scriptFile.toURL();//this.getClass().getResource("/scripts/"+source.getName()+".py");
            //          .out.println( urlHTML );
            //          .out.println( urlHTML.toExternalForm() );
            htmlPane.setPage(urlHTML);
            htmlPane.setEditable(false);
            JEPyperlinkListener myJEPHL = new JEPyperlinkListener(htmlPane);
            htmlPane.addHyperlinkListener(myJEPHL);
            myFrame.getContentPane().add(new JScrollPane(htmlPane));
            myFrame.pack();
            myFrame.setSize(640, 480);
            myFrame.show();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this,
                    VERSION_INFO + "\n" + "by kizura\n" + WDBearManager.EMAIL + "\n\n"
                            + "Could not open 'doc/html/index.html'",
                    "Warning " + VERSION_INFO, JOptionPane.WARNING_MESSAGE);
        }
    } else if (source.getText().equals(MENU_JDOCS)) {
        JFrame myFrame = new JFrame("doc/javadoc/index.html");
        //myFrame.setFont(   );
        URL urlHTML = null;
        try {
            JEditorPane htmlPane = new JEditorPane();
            //htmlPane.setFont(sourceFont);
            // .out.println("/scripts/"+source.getName()+".py");
            File scriptFile = new File("doc/javadoc/index.html");
            urlHTML = scriptFile.toURL();
            htmlPane.setPage(urlHTML);
            htmlPane.setEditable(false);
            JEPyperlinkListener myJEPHL = new JEPyperlinkListener(htmlPane);
            htmlPane.addHyperlinkListener(myJEPHL);
            myFrame.getContentPane().add(new JScrollPane(htmlPane));
            myFrame.pack();
            myFrame.setSize(640, 480);
            myFrame.show();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this,
                    VERSION_INFO + "\n" + "by kizura\n" + WDBearManager.EMAIL + "\n\n"
                            + "Could not open 'doc/javadoc/index.html'",
                    "Warning " + VERSION_INFO, JOptionPane.WARNING_MESSAGE);
        }
    } else if (source.getText().equals(MENU_CHECKUPDATE)) {
        Properties dbProps = null;
        String filName = PROPS_CHECK_UPDATE;
        try {
            dbProps = ReadPropertiesFile.readProperties(filName);
            String updFile = dbProps.getProperty(KEY_UPD_FILE);
            if (updFile == null) {
                JOptionPane.showMessageDialog(this,
                        VERSION_INFO + "\n" + "by kizura\n" + WDBearManager.EMAIL + "\n\n"
                                + "Could not find update information",
                        "Warning " + VERSION_INFO, JOptionPane.WARNING_MESSAGE);
                return;
            }
            String updSite = dbProps.getProperty(KEY_WDBMGR_SITE);
            if (updFile == null) {
                JOptionPane.showMessageDialog(this,
                        VERSION_INFO + "\n" + "by kizura\n" + WDBearManager.EMAIL + "\n\n"
                                + "Could not find SITE information",
                        "Warning " + VERSION_INFO, JOptionPane.WARNING_MESSAGE);
                return;
            }

            URL urlUpdScript = new URL(updFile);
            BufferedReader in = new BufferedReader(new InputStreamReader(urlUpdScript.openStream()));

            String versionTXT = in.readLine();
            String downloadName = in.readLine();
            in.close();

            if (versionTXT.equals(WDBearManager.VERSION_INFO)) {
                JOptionPane.showMessageDialog(this,
                        VERSION_INFO + "\n" + "by kizura\n" + WDBearManager.EMAIL + "\n\n"
                                + "You are using the latest version, no updates available",
                        "Info " + VERSION_INFO, JOptionPane.INFORMATION_MESSAGE);
                return;
            } else {
                // Read version.txt
                String versionInfo = (String) dbProps.getProperty(KEY_VERSION_INFO);
                URL urlversionInfo = new URL(versionInfo);
                BufferedReader brVInfo = new BufferedReader(new InputStreamReader(urlversionInfo.openStream()));
                StringBuffer sbuVInfo = new StringBuffer();
                String strLine = "";
                boolean foundStart = false;
                while ((strLine = brVInfo.readLine()) != null) {
                    if (strLine.startsWith("---")) {
                        break;
                    }
                    if (foundStart == true) {
                        sbuVInfo.append(strLine);
                        sbuVInfo.append("\n");
                        continue;
                    }
                    if (strLine.startsWith(versionTXT)) {
                        foundStart = true;
                        continue;
                    }
                }
                brVInfo.close();

                int n = JOptionPane.showConfirmDialog(this,
                        "New version available - Please visit " + updSite + "\n\n" + versionTXT + "\n" + "\n"
                                + "You are using version:\n" + WDBearManager.VERSION_INFO + "\n" + "\n"
                                + "Do you want to download this version?\n\n" + "Version information:\n"
                                + sbuVInfo.toString(),
                        VERSION_INFO + "by kizura", JOptionPane.YES_NO_OPTION);
                //          JOptionPane.showMessageDialog(this, VERSION_INFO + "\n"
                //              + "by kizura\n" + WDBManager.EMAIL + "\n\n"
                //              + "New version available - Please visit " + updSite,
                //              "Warning "
                //              + VERSION_INFO, JOptionPane.WARNING_MESSAGE);
                if (n == 0) {
                    JFileChooser chooser = new JFileChooser(new File("."));
                    chooser.setDialogTitle("Please select download location");
                    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

                    int returnVal = chooser.showOpenDialog(this);
                    if (returnVal == JFileChooser.APPROVE_OPTION) {
                        try {
                            URL urlUpd = new URL(downloadName);
                            BufferedInputStream bin = new BufferedInputStream(urlUpd.openStream());
                            System.out.println(
                                    new File(chooser.getSelectedFile(), urlUpd.getFile()).getAbsolutePath());
                            File thisFile = new File(chooser.getSelectedFile(), urlUpd.getFile());
                            BufferedOutputStream bout = new BufferedOutputStream(
                                    new FileOutputStream(thisFile));

                            byte[] bufFile = new byte[102400];
                            int bytesRead = 0;
                            while ((bytesRead = bin.read(bufFile)) != -1) {
                                bout.write(bufFile, 0, bytesRead);
                            }
                            bin.close();
                            bout.close();

                            JOptionPane.showMessageDialog(this,
                                    "Update downloaded successfully" + "\n" + "Please check '"
                                            + thisFile.getAbsolutePath() + "'",
                                    "Success " + WDBearManager.VERSION_INFO, JOptionPane.INFORMATION_MESSAGE);
                            //String msg = WriteCSV.writeCSV(chooser.getSelectedFile(), this.items);
                        } catch (Exception ex) {
                            String msg = ex.getMessage();
                            JOptionPane.showMessageDialog(this, msg + "\n" + "Error downloading update",
                                    "Error " + WDBearManager.VERSION_INFO, JOptionPane.ERROR_MESSAGE);
                        }
                    }
                } // user selected "download"
                return;
            }

        } catch (Exception ex) {
            ex.printStackTrace();
        }

    } else {
        System.exit(0);
    }

}

From source file:ffx.ui.KeywordPanel.java

/**
 * Give the user a File Dialog Box so they can select a key file.
 *///from  ww w .j  a v  a 2s  . c  o m
public void keyOpen() {
    if (fileOpen && KeywordComponent.isKeywordModified()) {
        int option = JOptionPane.showConfirmDialog(this, "Save Changes First", "Opening New File",
                JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);
        if (option == JOptionPane.CANCEL_OPTION) {
            return;
        } else if (option == JOptionPane.YES_OPTION) {
            keySave(currentKeyFile);
        }
        keyClear();
    }
    JFileChooser d = MainPanel.resetFileChooser();
    if (currentSystem != null) {
        File cwd = currentSystem.getFile();
        if (cwd != null && cwd.getParentFile() != null) {
            d.setCurrentDirectory(cwd.getParentFile());
        }
    }
    d.setAcceptAllFileFilterUsed(false);
    d.setFileFilter(MainPanel.keyFileFilter);
    d.setDialogTitle("Open KEY File");
    int result = d.showOpenDialog(this);
    if (result == JFileChooser.APPROVE_OPTION) {
        File newKeyFile = d.getSelectedFile();
        if (newKeyFile != null && newKeyFile.exists() && newKeyFile.canRead()) {
            keyOpen(newKeyFile);
        }
    }
}

From source file:com.cybercom.svp.machine.gui.MachineForm.java

private void buttomLoadFirmwareSettingFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttomLoadFirmwareSettingFileActionPerformed
    JFileChooser fileDialog = new JFileChooser();
    fileDialog.setDialogTitle("Select firmware file");

    FileNameExtensionFilter filter = new FileNameExtensionFilter("XML file", "xml");
    fileDialog.setFileFilter(filter);//  w  w  w.  j ava 2 s .  co m
    fileDialog.setDialogType(JFileChooser.OPEN_DIALOG);
    int result = fileDialog.showOpenDialog(this);
    if (result == JFileChooser.APPROVE_OPTION) {

        try {
            String xml = FileUtils.readFileToString(fileDialog.getSelectedFile());
            firmwareUpdateRequestSetting = xmlToObj(FirmwareUpdateRequest.class, xml);
            updateFirmwareSettings();

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:org.fhaes.fhsamplesize.view.FHSampleSize.java

/**
 * Open a JFileChooser and return the file that the user specified for saving. Takes a parameter that specifies the type of file. Either
 * TAB or PNG./* ww w .jav  a 2  s . c o  m*/
 * 
 * @return
 */
private File getFileFromSaveDialog(String fileTypeToSave) {

    String lastVisitedFolder = App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null);
    JFileChooser fc = new JFileChooser(lastVisitedFolder);
    File outputFile;

    if (fileTypeToSave == "TAB") {
        TABFilter filterTAB = new TABFilter();
        fc.addChoosableFileFilter(filterTAB);
        fc.setFileFilter(filterTAB);
        fc.setDialogTitle("Export table as text file...");

    } else if (fileTypeToSave == "PDF") {
        PDFFilter filterPDF = new PDFFilter();
        fc.addChoosableFileFilter(filterPDF);
        fc.setFileFilter(filterPDF);
        fc.setDialogTitle("Export chart as PDF...");
    }

    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setMultiSelectionEnabled(false);

    int returnVal = fc.showSaveDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        outputFile = fc.getSelectedFile();

        if (FileUtils.getExtension(outputFile.getAbsolutePath()) == "") {
            log.debug("Output file extension not set by user");

            if (fc.getFileFilter().getDescription().equals(new CSVFileFilter().getDescription())) {
                log.debug("Adding csv extension to output file name");
                outputFile = new File(outputFile.getAbsolutePath() + ".csv");
            } else if (fc.getFileFilter().getDescription().equals(new PDFFilter().getDescription())) {
                log.debug("Adding pdf extension to output file name");
                outputFile = new File(outputFile.getAbsolutePath() + ".pdf");
            }
        } else {
            log.debug("Output file extension set my user to '"
                    + FileUtils.getExtension(outputFile.getAbsolutePath()) + "'");
        }

        App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, outputFile.getAbsolutePath());
    } else {
        return null;
    }

    if (outputFile.exists()) {
        Object[] options = { "Overwrite", "No", "Cancel" };

        // notes about parameters: null (don't use custom icon), options (the titles of buttons), options[0] (default button title)
        int response = JOptionPane.showOptionDialog(App.mainFrame,
                "The file '" + outputFile.getName() + "' already exists.  Are you sure you want to overwrite?",
                "Confirm", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options,
                options[0]);

        if (response != JOptionPane.YES_OPTION)
            return null;
    }
    return outputFile;
}

From source file:org.biojava.bio.view.MotifAnalyzer.java

public void runMethod(MotifFinder method) {
    final JFileChooser fc = new JFileChooser();
    fc.setFileFilter(new Filter("fasta"));
    fc.setDialogTitle("Select Sequence File (in FASTA format)");
    int returnVal = JFileChooser.CANCEL_OPTION;
    if (datasetComboBox.getSelectedItem().equals(Dataset.unknown))
        returnVal = fc.showOpenDialog(MotifAnalyzer.this.mainFrame);

    if (!datasetComboBox.getSelectedItem().equals(Dataset.unknown)
            || (returnVal == JFileChooser.APPROVE_OPTION)) {
        try {/*from   w ww  .j a  v a 2 s . c o m*/
            final JFileChooser readDirectory = new JFileChooser();
            readDirectory.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            if (readDirectory.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) {
                Dataset dataset = (Dataset) datasetComboBox.getSelectedItem();
                int type = datasetTypeComboBox.getSelectedIndex();
                String fileName = (returnVal == JFileChooser.APPROVE_OPTION)
                        ? fc.getSelectedFile().getCanonicalPath()
                        : TompaDataset.getDatasetSequenceFileName(dataset);
                int i = Integer.parseInt(numOfMotifs.getText());
                int w = Integer.parseInt(motifWidth.getText());
                int t = Integer.parseInt(numOfTrials.getText());
                OrganismCode organism = OrganismCode.getOrganism(organismType.getSelectedIndex());
                log.info("Runninf method: " + method.name());
                log.info("FileName: " + fileName);
                log.info("Outputfile: " + readDirectory.getSelectedFile().getCanonicalPath());
                log.info("Dataset: " + dataset.name());
                log.info("DatasetType: " + type);
                controller.runAndEvaluate(method, fileName, i, w, t, organism, dataset,
                        readDirectory.getSelectedFile().getCanonicalPath());
                displayCharts();
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(mainFrame, "An Error occured", "Error", JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:com.emental.mindraider.ui.frames.MindRaiderMainWindow.java

private void exportActiveOutlineToAtom() {
    if (MindRaider.profile.getActiveOutline() == null) {
        JOptionPane.showMessageDialog(MindRaiderMainWindow.this,
                Messages.getString("MindRaiderJFrame.exportNotebookWarning"),
                Messages.getString("MindRaiderJFrame.exportError"), JOptionPane.ERROR_MESSAGE);
        return;/*from   w  w w. j  a va  2s. co m*/
    }

    JFileChooser fc = new JFileChooser();
    fc.setApproveButtonText(Messages.getString("MindRaiderJFrame.export"));
    fc.setControlButtonsAreShown(true);
    fc.setDialogTitle(Messages.getString("MindRaiderJFrame.chooseExportDirectory"));
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    // prepare directory
    String exportDirectory = MindRaider.profile.getHomeDirectory() + File.separator + "export" + File.separator
            + "sharing";
    Utils.createDirectory(exportDirectory);
    fc.setCurrentDirectory(new File(exportDirectory));
    int returnVal = fc.showOpenDialog(MindRaiderMainWindow.this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        String dstDirectory = fc.getSelectedFile().getAbsolutePath();
        Utils.createDirectory(dstDirectory);
        final String dstFileName = dstDirectory + File.separator + "MindRaider-"
                + MindRaider.outlineCustodian.getActiveNotebookNcName() + "-"
                + Utils.getCurrentDataTimeAsPrettyString() + ".atom.xml";
        logger.debug(Messages.getString("MindRaiderJFrame.exportingToFile", dstFileName));

        MindRaider.outlineCustodian.exportOutline(OutlineCustodian.FORMAT_ATOM, dstFileName);
    } else {
        logger.debug(Messages.getString("MindRaiderJFrame.exportCommandCancelledByUser"));
    }
}