List of usage examples for javax.swing JOptionPane JOptionPane
public JOptionPane(Object message, int messageType, int optionType, Icon icon, Object[] options, Object initialValue)
JOptionPane
to display a message with the specified message type, icon, and options, with the initially-selected option specified. From source file:esmska.gui.AboutFrame.java
private void licenseButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_licenseButtonActionPerformed //show licence try {/* w w w.jav a 2 s.c o m*/ logger.fine("Showing license..."); String license = IOUtils.toString(getClass().getResourceAsStream(RES + "license.txt"), "UTF-8"); final String agpl = IOUtils.toString(getClass().getResourceAsStream(RES + "gnu-agpl.txt"), "UTF-8"); license = MiscUtils.escapeHtml(license); license = license.replaceAll("GNU Affero General Public License", "<a href=\"agpl\">GNU Affero General Public License</a>"); final JTextPane tp = new JTextPane(); tp.setContentType("text/html; charset=UTF-8"); tp.setText("<html><pre>" + license + "</pre></html>"); tp.setEditable(false); Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); tp.setPreferredSize(new Dimension((int) d.getWidth() / 2, (int) d.getHeight() / 2)); //reasonable size tp.setCaretPosition(0); //make links clickable tp.addHyperlinkListener(new HyperlinkListener() { @Override public void hyperlinkUpdate(final HyperlinkEvent e) { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { logger.fine("Showing GNU AGPL..."); tp.setText(null); tp.setContentType("text/plain"); tp.setText(agpl); tp.setCaretPosition(0); } } }); String option = l10n.getString("AboutFrame.Acknowledge"); JOptionPane op = new JOptionPane(new JScrollPane(tp), JOptionPane.INFORMATION_MESSAGE, JOptionPane.DEFAULT_OPTION, null, new Object[] { option }, option); JDialog dialog = op.createDialog(this, l10n.getString("AboutFrame.License")); dialog.setResizable(true); dialog.pack(); dialog.setVisible(true); } catch (IOException ex) { logger.log(Level.WARNING, "Could not show license", ex); } }
From source file:esmska.gui.AboutFrame.java
private void creditsButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_creditsButtonActionPerformed //show credits try {/*from w ww. j a va 2 s. co m*/ logger.fine("Showing credits..."); String credits = IOUtils.toString(getClass().getResourceAsStream(RES + "credits.html"), "UTF-8"); String translators = l10n.getString("Translators"); if ("translator-credits".equals(translators)) { //there are no translators mentioned translators = ""; } else { translators = translators.replaceAll("\n", "<br>\n").replaceAll("\n ", "\n "); //add hyperlinks to the Launchpad URLs translators = translators.replaceAll("(https://[^<]*)", "<a href=\"$1\">$1</a>"); } String document = MessageFormat.format(credits, l10n.getString("Credits.authors"), l10n.getString("Credits.contributors"), l10n.getString("Credits.graphics"), l10n.getString("Credits.sponsors"), l10n.getString("Credits.translators"), translators, Links.DONATORS, l10n.getString("Credits.moreDonators"), MessageFormat.format(l10n.getString("Credits.packagers"), Links.DOWNLOAD)); JTextPane tp = new JTextPane(); tp.setContentType("text/html; charset=UTF-8"); tp.setText(document); tp.setEditable(false); tp.setPreferredSize(new Dimension(450, 400)); tp.setCaretPosition(0); //make links clickable tp.addHyperlinkListener(new HyperlinkListener() { @Override public void hyperlinkUpdate(final HyperlinkEvent e) { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED && Desktop.isDesktopSupported()) { try { logger.fine("Browsing URL: " + e.getURL()); Desktop.getDesktop().browse(e.getURL().toURI()); } catch (Exception ex) { logger.log(Level.SEVERE, "Can't browse hyperlink: " + e.getURL(), ex); } } } }); String option = l10n.getString("AboutFrame.Thank_you"); JOptionPane op = new JOptionPane(new JScrollPane(tp), JOptionPane.INFORMATION_MESSAGE, JOptionPane.DEFAULT_OPTION, null, new Object[] { option }, option); JDialog dialog = op.createDialog(this, l10n.getString("AboutFrame.Credits")); dialog.setResizable(true); dialog.pack(); dialog.setVisible(true); } catch (IOException e) { logger.log(Level.WARNING, "Could not show credits", e); } }
From source file:gda.gui.mca.McaGUI.java
private void makeTcaControlDialog() { if (tcaControlPanel == null) { tcaControlPanel = new TcaPanel(); tcaDialog = new JDialog(); Object[] options = { "OK" }; Object[] array = { tcaControlPanel }; // Create the JOptionPane. final JOptionPane optionPane = new JOptionPane(array, JOptionPane.PLAIN_MESSAGE, JOptionPane.YES_OPTION, null, options, options[0]); optionPane.addPropertyChangeListener(new PropertyChangeListener() { @Override/* w w w. j a va 2s . c o m*/ public void propertyChange(PropertyChangeEvent e) { String prop = e.getPropertyName(); if (isVisible() && (e.getSource() == optionPane) && (JOptionPane.VALUE_PROPERTY.equals(prop) || JOptionPane.INPUT_VALUE_PROPERTY.equals(prop))) { Object value = optionPane.getValue(); if (value == JOptionPane.UNINITIALIZED_VALUE) { // ignore reset return; } // Reset the JOptionPane's value. // If you don't do this, then if the user // presses the same button next time, no // property change event will be fired. optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE); if ("OK".equals(value)) { tcaDialog.setVisible(false); } } } }); tcaDialog.setContentPane(optionPane); tcaDialog.pack(); tcaDialog.setTitle("TCA Controls"); tcaDialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); } }
From source file:gda.gui.mca.McaGUI.java
private void makeAdcControlDialog() { if (adcControlPanel == null) { adcControlPanel = new AdcPanel(); adcDialog = new JDialog(); Object[] options = { "OK" }; Object[] array = { adcControlPanel }; // Create the JOptionPane. final JOptionPane optionPane = new JOptionPane(array, JOptionPane.PLAIN_MESSAGE, JOptionPane.YES_OPTION, null, options, options[0]); optionPane.addPropertyChangeListener(new PropertyChangeListener() { @Override/*from w w w . j av a 2 s . c om*/ public void propertyChange(PropertyChangeEvent e) { String prop = e.getPropertyName(); if (isVisible() && (e.getSource() == optionPane) && (JOptionPane.VALUE_PROPERTY.equals(prop) || JOptionPane.INPUT_VALUE_PROPERTY.equals(prop))) { Object value = optionPane.getValue(); if (value == JOptionPane.UNINITIALIZED_VALUE) { // ignore reset return; } // Reset the JOptionPane's value. // If you don't do this, then if the user // presses the same button next time, no // property change event will be fired. optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE); if ("OK".equals(value)) { adcDialog.setVisible(false); } } } }); adcDialog.setContentPane(optionPane); adcDialog.pack(); adcDialog.setTitle("ADC Controls"); adcDialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); } }
From source file:DialogDemo.java
/** Creates the reusable dialog. */ public CustomDialog(Frame aFrame, String aWord, DialogDemo parent) { super(aFrame, true); dd = parent;/*from ww w . j ava 2 s .co m*/ magicWord = aWord.toUpperCase(); setTitle("Quiz"); textField = new JTextField(10); // Create an array of the text and components to be displayed. String msgString1 = "What was Dr. SEUSS's real last name?"; String msgString2 = "(The answer is \"" + magicWord + "\".)"; Object[] array = { msgString1, msgString2, textField }; // Create an array specifying the number of dialog buttons // and their text. Object[] options = { btnString1, btnString2 }; // Create the JOptionPane. optionPane = new JOptionPane(array, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null, options, options[0]); // Make this dialog display it. setContentPane(optionPane); // Handle window closing correctly. setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { /* * Instead of directly closing the window, we're going to change the * JOptionPane's value property. */ optionPane.setValue(new Integer(JOptionPane.CLOSED_OPTION)); } }); // Ensure the text field always gets the first focus. addComponentListener(new ComponentAdapter() { public void componentShown(ComponentEvent ce) { textField.requestFocusInWindow(); } }); // Register an event handler that puts the text into the option pane. textField.addActionListener(this); // Register an event handler that reacts to option pane state changes. optionPane.addPropertyChangeListener(this); }
From source file:org.docx4all.swing.ExternalHyperlinkDialog.java
public ExternalHyperlinkDialog(WordMLEditor wmlEditor, String sourceFileVFSUrlPath, HyperlinkML hyperlinkML, FileNameExtensionFilter fileFilter) { super(wmlEditor.getWindowFrame(), true); this.sourceFileVFSUrlPath = sourceFileVFSUrlPath; this.hyperlinkML = hyperlinkML; this.fileFilter = fileFilter; this.value = CANCEL_BUTTON_TEXT; setTitle("External Hyperlink Setup"); Object[] options = { OK_BUTTON_TEXT, CANCEL_BUTTON_TEXT }; Object[] array = { createContentPanel(sourceFileVFSUrlPath, hyperlinkML) }; this.optionPane = new JOptionPane(array, JOptionPane.PLAIN_MESSAGE, JOptionPane.YES_OPTION, null, options, options[0]);/* ww w. j a v a2 s . co m*/ //Make this dialog display it. setContentPane(this.optionPane); //Handle window closing correctly. setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { /* * Instead of directly closing the window, we're going to change * the JOptionPane's value property. */ ExternalHyperlinkDialog.this.optionPane.setValue(new Integer(JOptionPane.CLOSED_OPTION)); } }); //Register an event handler that reacts to option pane state changes. this.optionPane.addPropertyChangeListener(this); }
From source file:org.myrobotlab.service.MarySpeech.java
private void showProgressPanel(List<ComponentDescription> comps, boolean install) { final ProgressPanel pp = new ProgressPanel(comps, install); final JOptionPane optionPane = new JOptionPane(pp, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION, null, new String[] { "Abort" }, "Abort"); // optionPane.setPreferredSize(new Dimension(640,480)); final JDialog dialog = new JDialog((Frame) null, "Progress", false); dialog.setContentPane(optionPane);/* w w w.j av a2 s.co m*/ optionPane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { String prop = e.getPropertyName(); if (dialog.isVisible() && (e.getSource() == optionPane) && (prop.equals(JOptionPane.VALUE_PROPERTY))) { pp.requestExit(); dialog.setVisible(false); } } }); dialog.pack(); dialog.setVisible(true); new Thread(pp).start(); }
From source file:xtrememp.update.SoftwareUpdate.java
public static void showCheckForUpdatesDialog() { checkForUpdatesDialog = new JDialog(XtremeMP.getInstance().getMainFrame(), tr("Dialog.SoftwareUpdate"), true);/* www . j av a2 s . co m*/ JPanel panel = new JPanel(new BorderLayout(0, 10)); panel.add(new JLabel(tr("Dialog.SoftwareUpdate.CheckingForUpdates")), BorderLayout.CENTER); JProgressBar progressBar = new JProgressBar(); progressBar.setIndeterminate(true); progressBar.setPreferredSize(new Dimension(250, 20)); panel.add(progressBar, BorderLayout.SOUTH); JButton cancelButton = new JButton(tr("Button.Cancel")); cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (checkForUpdatesWorker != null && !checkForUpdatesWorker.isDone()) { checkForUpdatesWorker.cancel(true); } checkForUpdatesDialog.dispose(); } }); JOptionPane optionPane = new JOptionPane(panel, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION, null, new Object[] { cancelButton }, cancelButton); checkForUpdatesDialog.setContentPane(optionPane); checkForUpdatesDialog.pack(); checkForUpdatesDialog.setResizable(false); checkForUpdatesDialog.setLocationRelativeTo(checkForUpdatesDialog.getParent()); checkForUpdatesDialog.getRootPane().setDefaultButton(cancelButton); checkForUpdatesDialog.setVisible(true); }