Example usage for javax.swing JOptionPane showMessageDialog

List of usage examples for javax.swing JOptionPane showMessageDialog

Introduction

In this page you can find the example usage for javax.swing JOptionPane showMessageDialog.

Prototype

public static void showMessageDialog(Component parentComponent, Object message, String title, int messageType)
        throws HeadlessException 

Source Link

Document

Brings up a dialog that displays a message using a default icon determined by the messageType parameter.

Usage

From source file:com.GoEuro.paseOperation.ParseObject.java

public static List<City> parseArray(String jsonArray) {

    List<City> cities = new ArrayList<>();
    try {/*from   w  w w. java 2 s . c  o  m*/
        JSONArray jsonarray = new JSONArray(jsonArray);
        for (int i = 0; i < jsonarray.length(); i++) {
            JSONObject jsonobject = jsonarray.getJSONObject(i);
            City city = parseJson(jsonobject.toString());
            cities.add(city);
            System.out.println(city.toString());
        }
    } catch (JSONException ex) {
        System.err.println("ERROR: " + ex.getMessage());
        JOptionPane.showMessageDialog(null, "Error parsing Json Array",
                "Error parsing Json Array: " + ex.getMessage(), JOptionPane.ERROR_MESSAGE);
    }
    return cities;
}

From source file:Main.java

/**
 * A utility method for displaying a dialog.
 *
 * @param parentComponent/*from  www .  ja v a  2  s .c  o  m*/
 * @param message
 * @param title
 * @return
 */
public static int showDialog(Component parentComponent, Object message, String title) {
    JOptionPane.showMessageDialog(parentComponent, message, title, JOptionPane.PLAIN_MESSAGE);

    return -1;
}

From source file:Dialogs.java

public static void showNotYetImplemented(Component owner) {
    JOptionPane.showMessageDialog(owner, "Not Yet Implemented", "", JOptionPane.INFORMATION_MESSAGE);
}

From source file:it.ferogrammer.ui.MainAppFrame.java

private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
    JOptionPane op = new JOptionPane();
    op.showMessageDialog(this,
            "Copyright (c) 2016 Enea Parimbelli (https://github.com/eparimbelli/FeroGrammer) - terms of the MIT license apply",
            "FeroGrammer v1.1", JOptionPane.INFORMATION_MESSAGE);
}

From source file:com.seanmadden.fast.ldap.main.Main.java

/**
 * The Main Event./*from  www  .j av  a 2  s.  c om*/
 * 
 * @param args
 */
@SuppressWarnings("static-access")
public static void main(String[] args) {
    BasicConfigurator.configure();
    log.debug("System initializing");
    try {
        Logger.getRootLogger().addAppender(
                new FileAppender(new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN), "log.log"));
    } catch (IOException e1) {
        log.error("Unable to open the log file..?");
    }

    /*
     * Initialize the configuration engine.
     */
    XMLConfiguration config = new XMLConfiguration();
    config.setListDelimiter('|');

    /*
     * Initialize the Command-Line parsing engine.
     */
    CommandLineParser parser = new PosixParser();
    Options opts = new Options();
    opts.addOption(OptionBuilder.withLongOpt("config-file").hasArg()
            .withDescription("The configuration file to load").withArgName("config.xml").create("c"));

    opts.addOption(OptionBuilder.withLongOpt("profile").hasArg().withDescription("The profile to use")
            .withArgName("Default").create("p"));

    opts.addOption(OptionBuilder.withLongOpt("password").hasArg().withDescription("Password to connect with")
            .withArgName("password").create("P"));

    opts.addOption(OptionBuilder.withLongOpt("debug").hasArg(false).create('d'));

    opts.addOption(OptionBuilder.withLongOpt("verbose").hasArg(false).create('v'));

    File configurationFile = new File("config.xml");

    try {
        // Parse the command-line options
        CommandLine cmds = parser.parse(opts, args);

        if (!cmds.hasOption('p')) {
            Logger.getRootLogger().addAppender(new GuiErrorAlerter(Level.ERROR));
        }

        Logger.getRootLogger().setLevel(Level.ERROR);
        if (cmds.hasOption('v')) {
            Logger.getRootLogger().setLevel(Level.INFO);
        }
        if (cmds.hasOption('d')) {
            Logger.getRootLogger().setLevel(Level.DEBUG);
        }

        log.debug("Enabling configuration file parsing");
        // The user has given us a file to parse.
        if (cmds.hasOption("c")) {
            configurationFile = new File(cmds.getOptionValue("c"));
        }
        log.debug("Config file: " + configurationFile);

        // Load the configuration file
        if (configurationFile.exists()) {
            config.load(configurationFile);
        } else {
            log.error("Cannot find config file");
        }

        /*
         * Convert the profiles into memory
         */
        Vector<ConnectionProfile> profs = new Vector<ConnectionProfile>();
        List<?> profList = config.configurationAt("Profiles").configurationsAt("Profile");
        for (Object p : profList) {
            SubnodeConfiguration profile = (SubnodeConfiguration) p;
            String name = profile.getString("[@name]");
            String auth = profile.getString("LdapAuthString");
            String server = profile.getString("LdapServerString");
            String group = profile.getString("LdapGroupsLocation");
            ConnectionProfile prof = new ConnectionProfile(name, server, auth, group);
            profs.add(prof);
        }
        ConnectionProfile prof = null;
        if (!cmds.hasOption('p')) {
            /*
             * Deploy the profile selector, to select a profile
             */
            ProfileSelector profSel = new ProfileSelector(profs);
            prof = profSel.getSelection();
            if (prof == null) {
                return;
            }
            /*
             * Empty the profiles and load a clean copy - then save it back
             * to the file
             */
            config.clearTree("Profiles");
            for (ConnectionProfile p : profSel.getProfiles()) {
                config.addProperty("Profiles.Profile(-1)[@name]", p.getName());
                config.addProperty("Profiles.Profile.LdapAuthString", p.getLdapAuthString());
                config.addProperty("Profiles.Profile.LdapServerString", p.getLdapServerString());
                config.addProperty("Profiles.Profile.LdapGroupsLocation", p.getLdapGroupsString());
            }
            config.save(configurationFile);
        } else {
            for (ConnectionProfile p : profs) {
                if (p.getName().equals(cmds.getOptionValue('p'))) {
                    prof = p;
                    break;
                }
            }
        }

        log.info("User selected " + prof);

        String password = "";
        if (cmds.hasOption('P')) {
            password = cmds.getOptionValue('P');
        } else {
            password = PasswordPrompter.promptForPassword("Password?");
        }

        if (password.equals("")) {
            return;
        }

        LdapInterface ldap = new LdapInterface(prof.getLdapServerString(), prof.getLdapAuthString(),
                prof.getLdapGroupsString(), password);

        /*
         * Gather options information from the configuration engine for the
         * specified report.
         */
        Hashtable<String, Hashtable<String, ReportOption>> reportDataStructure = new Hashtable<String, Hashtable<String, ReportOption>>();
        List<?> repConfig = config.configurationAt("Reports").configurationsAt("Report");
        for (Object p : repConfig) {
            SubnodeConfiguration repNode = (SubnodeConfiguration) p;

            // TODO Do something with the report profile.
            // Allowing the user to deploy "profiles" is a nice feature
            // String profile = repNode.getString("[@profile]");

            String reportName = repNode.getString("[@report]");
            Hashtable<String, ReportOption> reportOptions = new Hashtable<String, ReportOption>();
            reportDataStructure.put(reportName, reportOptions);
            // Loop through the options and add each to the table.
            for (Object o : repNode.configurationsAt("option")) {
                SubnodeConfiguration option = (SubnodeConfiguration) o;
                String name = option.getString("[@name]");
                String type = option.getString("[@type]");
                String value = option.getString("[@value]");

                ReportOption ro = new ReportOption();
                ro.setName(name);

                if (type.toLowerCase().equals("boolean")) {
                    ro.setBoolValue(Boolean.parseBoolean(value));
                } else if (type.toLowerCase().equals("integer")) {
                    ro.setIntValue(Integer.valueOf(value));
                } else {
                    // Assume a string type here then.
                    ro.setStrValue(value);
                }
                reportOptions.put(name, ro);
                log.debug(ro);
            }
        }
        System.out.println(reportDataStructure);

        /*
         * At this point, we now need to deploy the reports window to have
         * the user pick a report and select some happy options to allow
         * that report to work. Let's go.
         */
        /*
         * Deploy the Reports selector, to select a report
         */
        Reports.getInstance().setLdapConnection(ldap);
        ReportsWindow reports = new ReportsWindow(Reports.getInstance().getAllReports(), reportDataStructure);
        Report report = reports.getSelection();
        if (report == null) {
            return;
        }
        /*
         * Empty the profiles and load a clean copy - then save it back to
         * the file
         */
        config.clearTree("Reports");
        for (Report r : Reports.getInstance().getAllReports()) {
            config.addProperty("Reports.Report(-1)[@report]", r.getClass().getCanonicalName());
            config.addProperty("Reports.Report[@name]", "Standard");
            for (ReportOption ro : r.getOptions().values()) {
                config.addProperty("Reports.Report.option(-1)[@name]", ro.getName());
                config.addProperty("Reports.Report.option[@type]", ro.getType());
                config.addProperty("Reports.Report.option[@value]", ro.getStrValue());
            }
        }
        config.save(configurationFile);
        ProgressBar bar = new ProgressBar();
        bar.start();
        report.execute();
        ASCIIFormatter format = new ASCIIFormatter();
        ReportResult res = report.getResult();
        format.format(res, new File(res.getForName() + "_" + res.getReportName() + ".txt"));
        bar.stop();

        JOptionPane.showMessageDialog(null,
                "The report is at " + res.getForName() + "_" + res.getReportName() + ".txt", "Success",
                JOptionPane.INFORMATION_MESSAGE);

    } catch (ParseException e) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("FAST Ldap Searcher", opts);
    } catch (ConfigurationException e) {
        e.printStackTrace();
        log.fatal("OH EM GEES!  Configuration errors.");
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:Main.java

/**
 * Mostra uma caixa de menssagem para que seja ensirido um valor.
 * @param frame//  w  w  w .j  a  va2s  .  c o m
 * @param texto
 * @param title
 * @param valorInicial
 * @param type
 * @return
 * @author Thiago Benega
 * @since 13/04/2009
 */
public static String showTextboxDialog(javax.swing.JFrame frame, String texto, String title,
        String valorInicial, int type) {
    Object txt = null;
    JDialog jDialog = new JDialog();
    jDialog.setTitle(title);
    jDialog.setFocusableWindowState(true);

    if (frame != null) {
        frame.setExtendedState(Frame.ICONIFIED);
        frame.pack();
        frame.setExtendedState(Frame.MAXIMIZED_BOTH);
    }

    switch (type) {
    case JOptionPane.OK_CANCEL_OPTION:
        txt = JOptionPane.showInputDialog(jDialog, texto, title, type, null, null, valorInicial);//.toString();
        break;
    case JOptionPane.YES_NO_OPTION:
        txt = JOptionPane.showConfirmDialog(jDialog, texto, title, type, JOptionPane.INFORMATION_MESSAGE);
        break;
    default:
        JOptionPane.showMessageDialog(jDialog, texto, title, type);
        break;
    }

    jDialog = null;
    return txt != null ? txt.toString() : null;

}

From source file:it.ferogrammer.ui.MainAppFrame.java

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
    if (jPanel2.getComponentCount() == 1 && (jPanel2.getComponent(0) instanceof ElectropherogramChartPanel)) {
        ElectropherogramChartPanel chartPanel = (ElectropherogramChartPanel) jPanel2.getComponent(0);
        final JFileChooser fc = new JFileChooser();
        //            fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        int returnVal = fc.showSaveDialog(chartPanel);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            if (!file.getName().endsWith(".png")) {
                int extindex = file.getPath().indexOf('.') == -1 ? file.getPath().length()
                        : file.getPath().indexOf('.');
                file = new File(file.getPath().substring(0, extindex) + ".png");
            }/*from  w  w  w .  j ava  2  s  .  co  m*/
            try {
                ChartUtilities.saveChartAsPNG(file, chartPanel.getChart(), chartPanel.getWidth(),
                        chartPanel.getHeight());
            } catch (IOException ex) {
                JOptionPane op = new JOptionPane();
                op.showMessageDialog(jPanel2, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
            }
        }
    } else {
        JOptionPane op = new JOptionPane();
        op.showMessageDialog(jPanel2, "Cannot export image", "Error", JOptionPane.ERROR_MESSAGE);
    }
}

From source file:Main.java

/**
 * Browse to a folder./*w  w w.  j  a v  a 2s.co m*/
 * 
 * @param file the path
 * @param component the component
 */
public static void browseDir(File file, Component component) {
    try {
        Desktop.getDesktop().browse(new URL("file://" + file.getAbsolutePath()).toURI());
    } catch (IOException e) {
        JOptionPane.showMessageDialog(component,
                "Unable to open '" + file.getAbsolutePath() + "'. Maybe it doesn't exist?", "Open failed",
                JOptionPane.ERROR_MESSAGE);
    } catch (URISyntaxException e) {
    }
}

From source file:Main.java

/**
 * visualizzazione messaggio HTML/*from w  ww  .ja  v  a2  s.co m*/
 *
 * @param pFrame frame di provenienza (di solito e' <code>this</code>).
 * @param pTask task di provenienza del messaggio (di solito e'
 * <code>TASK_NAME</code>).
 * @param pMessaggio messaggio da visualizzare
 */
public static void dispAlert(JFrame pFrame, String pTask, String pMessaggio) {
    //
    JOptionPane.showMessageDialog(pFrame, formattaHTML(pMessaggio), ALERT_TITLE, JOptionPane.OK_CANCEL_OPTION);
}

From source file:Main.java

/**
 * Displays a message dialog with given information.
 */// w  w  w. java2s.  co  m
public static void showInformationDialog(Component component, String message) {
    final JPanel panel = new JPanel(new BorderLayout(5, 5));

    final JLabel messageLabel = new JLabel(message);
    messageLabel.setFont(new Font("Dialog", Font.BOLD, messageLabel.getFont().getSize()));

    panel.add(messageLabel, BorderLayout.CENTER);

    // Adjust stack trace dimensions
    final Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
    screenDimension.setSize(screenDimension.getWidth() * 0.7, screenDimension.getHeight() * 0.7);
    final Dimension maxStackTraceDimension = new Dimension(500, 500);
    maxStackTraceDimension.setSize(Math.min(maxStackTraceDimension.getWidth(), screenDimension.getWidth()),
            Math.min(maxStackTraceDimension.getHeight(), screenDimension.getHeight()));

    JOptionPane.showMessageDialog(component, panel, "Information", JOptionPane.INFORMATION_MESSAGE);
}