List of usage examples for javax.swing JOptionPane JOptionPane
public JOptionPane(Object message, int messageType)
JOptionPane
to display a message with the specified message type and the default options, From source file:org.isatools.isacreatorconfigurator.configui.DataEntryPanel.java
private void showMessagePane(String message, int messageType) { final JOptionPane optionPane = new JOptionPane("<html>" + message + "</html>", JOptionPane.OK_OPTION); UIHelper.renderComponent(optionPane, UIHelper.VER_12_PLAIN, UIHelper.DARK_GREEN_COLOR, false); if (messageType == JOptionPane.ERROR_MESSAGE) { optionPane.setIcon(warningIcon); } else {/* w ww. ja v a2 s. c o m*/ optionPane.setIcon(informationIcon); } optionPane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (event.getPropertyName().equals(JOptionPane.VALUE_PROPERTY)) { applicationContainer.hideSheet(); } } }); SwingUtilities.invokeLater(new Runnable() { public void run() { applicationContainer.showJDialogAsSheet(optionPane.createDialog(getThis(), "Message")); } }); }
From source file:org.jab.docsearch.DocSearch.java
/** * Does the actual work for Displaying an informational dialog - invoked via * a MessageRunner so as not to be on the dispatch (GUI) thread * * @see MessageRunner/*from w w w . ja v a 2 s. c o m*/ */ public void showMessageDialog(String title, String body) { if (!isLoading && env.isGUIMode()) { int messageType = JOptionPane.INFORMATION_MESSAGE; if (title.toLowerCase().indexOf(I18n.getString("lower_error")) != -1) { messageType = JOptionPane.ERROR_MESSAGE; } JOptionPane pane = new JOptionPane(body, messageType); JDialog dialog = pane.createDialog(this, title); dialog.setVisible(true); } else { logger.info("showMessageDialog() \n* * * " + title + " * * *\n\t" + body); } }
From source file:org.tellervo.desktop.prefs.Prefs.java
private static boolean cantSave(Exception e) { JPanel message = new JPanel(new BorderLayout(0, 8)); // (hgap,vgap) message.add(new JLabel(I18n.getText("error.prefs_cant_save")), BorderLayout.NORTH); // -- dialog with optionpane (warning?) JOptionPane optionPane = new JOptionPane(message, JOptionPane.ERROR_MESSAGE); JDialog dialog = optionPane.createDialog(null /* ? */, I18n.getText("error.prefs_cant_save_title")); // -- buttons: cancel, try again. optionPane.setOptions(new String[] { I18n.getText("question.try_again"), I18n.getText("general.cancel") }); // -- disclosure triangle with scrollable text area: click for // details... (stacktrace) JComponent stackTrace = new JScrollPane(new JTextArea(BugReport.getStackTrace(e), 10, 60)); JDisclosureTriangle v = new JDisclosureTriangle(I18n.getText("bug.click_for_details"), stackTrace, false); message.add(v, BorderLayout.CENTER); // -- checkbox: don't warn me again JCheckBox dontWarnCheckbox = new JCheckBox(I18n.getText("bug.dont_warn_again"), false); dontWarnCheckbox.addActionListener(new AbstractAction() { private static final long serialVersionUID = 1L; public void actionPerformed(ActionEvent e) { dontWarn = !dontWarn;/*w w w. j a v a 2 s . c om*/ } }); // FIXME: consolidate |message| panel construction with Layout methods message.add(dontWarnCheckbox, BorderLayout.SOUTH); // show dialog dialog.pack(); dialog.setResizable(false); dialog.setVisible(true); // return true if "try again" is clicked return optionPane.getValue().equals(I18n.getText("try_again")); }
From source file:processing.app.Editor.java
/** * Check if the sketch is modified and ask user to save changes. * @return false if canceling the close/quit operation *//*from ww w . ja v a 2 s. c o m*/ protected boolean checkModified() { if (!sketch.isModified()) return true; // As of Processing 1.0.10, this always happens immediately. // http://dev.processing.org/bugs/show_bug.cgi?id=1456 toFront(); String prompt = I18n.format(_("Save changes to \"{0}\"? "), sketch.getName()); if (!OSUtils.isMacOS()) { int result = JOptionPane.showConfirmDialog(this, prompt, _("Close"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); switch (result) { case JOptionPane.YES_OPTION: return handleSave(true); case JOptionPane.NO_OPTION: return true; // ok to continue case JOptionPane.CANCEL_OPTION: case JOptionPane.CLOSED_OPTION: // Escape key pressed return false; default: throw new IllegalStateException(); } } else { // This code is disabled unless Java 1.5 is being used on Mac OS X // because of a Java bug that prevents the initial value of the // dialog from being set properly (at least on my MacBook Pro). // The bug causes the "Don't Save" option to be the highlighted, // blinking, default. This sucks. But I'll tell you what doesn't // suck--workarounds for the Mac and Apple's snobby attitude about it! // I think it's nifty that they treat their developers like dirt. // Pane formatting adapted from the quaqua guide // http://www.randelshofer.ch/quaqua/guide/joptionpane.html JOptionPane pane = new JOptionPane(_("<html> " + "<head> <style type=\"text/css\">" + "b { font: 13pt \"Lucida Grande\" }" + "p { font: 11pt \"Lucida Grande\"; margin-top: 8px }" + "</style> </head>" + "<b>Do you want to save changes to this sketch<BR>" + " before closing?</b>" + "<p>If you don't save, your changes will be lost."), JOptionPane.QUESTION_MESSAGE); String[] options = new String[] { _("Save"), _("Cancel"), _("Don't Save") }; pane.setOptions(options); // highlight the safest option ala apple hig pane.setInitialValue(options[0]); // on macosx, setting the destructive property places this option // away from the others at the lefthand side pane.putClientProperty("Quaqua.OptionPane.destructiveOption", new Integer(2)); JDialog dialog = pane.createDialog(this, null); dialog.setVisible(true); Object result = pane.getValue(); if (result == options[0]) { // save (and close/quit) return handleSave(true); } else if (result == options[2]) { // don't save (still close/quit) return true; } else { // cancel? return false; } } }