List of usage examples for javax.swing JOptionPane JOptionPane
public JOptionPane(Object message, int messageType, int optionType, Icon icon, Object[] options)
JOptionPane
to display a message with the specified message type, icon, and options. From source file:JOptionPaneDemonstrationLocalized.java
public static void main(String[] argv) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); Font unicodeFont = new Font("LucidaSans", Font.PLAIN, 12); ResourceBundle bundle = ResourceBundle.getBundle("JOptionPaneResources", Locale.getDefault()); String[] textMessages = new String[3]; textMessages[0] = bundle.getString("Yes"); textMessages[1] = bundle.getString("No"); textMessages[2] = bundle.getString("Cancel"); JOptionPane jop = new JOptionPane(bundle.getString("MessageText"), JOptionPane.ERROR_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, textMessages); JDialog jopDialog = jop.createDialog(null, bundle.getString("TitleText")); jop.setFont(unicodeFont);/*from w w w. j a v a2s . c o m*/ jopDialog.setVisible(true); Object userSelection = jop.getValue(); }
From source file:Main.java
public void launchDialog() { JButton findButton = new JButton("Find"); findButton.addActionListener(e -> { int start = text.getText().indexOf("is"); int end = start + "is".length(); if (start != -1) { text.requestFocus();//w w w . jav a 2s . c om text.select(start, end); } }); JButton cancelButton = new JButton("Cancel"); JOptionPane optionPane = new JOptionPane("Do you understand?", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null, new Object[] { findButton, cancelButton }); JDialog dialog = new JDialog(frame, "Click a button", false); cancelButton.addActionListener(e -> dialog.setVisible(false)); dialog.setContentPane(optionPane); dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); dialog.setLocation(100, 100); dialog.pack(); dialog.setVisible(true); }
From source file:de.tudarmstadt.ukp.clarin.webanno.webapp.standalone.StandaloneShutdownDialog.java
private void displayShutdownDialog() { String serverId = ServerDetector.getServerId(); log.info("Running in: " + (serverId != null ? serverId : "unknown server")); log.info("Console: " + ((System.console() != null) ? "available" : "not available")); log.info("Headless: " + (GraphicsEnvironment.isHeadless() ? "yes" : "no")); // Show this only when run from the standalone JAR via a double-click if (System.console() == null && !GraphicsEnvironment.isHeadless() && ServerDetector.isWinstone()) { log.info("If you are running WebAnno in a server environment, please use '-Djava.awt.headless=true'"); EventQueue.invokeLater(new Runnable() { @Override//from ww w . j av a2s .com public void run() { final JOptionPane optionPane = new JOptionPane(new JLabel( "<HTML>WebAnno is running now and can be accessed via <a href=\"http://localhost:8080\">http://localhost:8080</a>.<br>" + "WebAnno works best with the browsers Google Chrome or Safari.<br>" + "Use this dialog to shut WebAnno down.</HTML>"), JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_OPTION, null, new String[] { "Shutdown" }); final JDialog dialog = new JDialog((JFrame) null, "WebAnno", true); dialog.setContentPane(optionPane); dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); dialog.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent we) { // Avoid closing window by other means than button } }); optionPane.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent aEvt) { if (dialog.isVisible() && (aEvt.getSource() == optionPane) && (aEvt.getPropertyName().equals(JOptionPane.VALUE_PROPERTY))) { System.exit(0); } } }); dialog.pack(); dialog.setVisible(true); } }); } else { log.info("Running in server environment or from command line: disabling interactive shutdown dialog."); } }
From source file:net.sf.nmedit.nomad.core.Nomad.java
public void export() { Document doc = getDocumentManager().getSelection(); if (!(doc instanceof Transferable)) return;// www .j a v a2s. c o m Transferable transferable = (Transferable) doc; String title = doc.getTitle(); if (title == null) title = "Export"; else title = "Export '" + title + "'"; JComboBox src = new JComboBox(transferable.getTransferDataFlavors()); src.setRenderer(new DefaultListCellRenderer() { /** * */ private static final long serialVersionUID = -4553255745845039428L; public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { String text; if (value instanceof DataFlavor) { DataFlavor flavor = (DataFlavor) value; String mimeType = flavor.getMimeType(); String humanRep = flavor.getHumanPresentableName(); String charset = flavor.getParameter("charset"); if (mimeType == null) text = "?"; else { text = mimeType; int ix = text.indexOf(';'); if (ix >= 0) text = text.substring(0, ix).trim(); } if (charset != null) text += "; charset=" + charset; if (humanRep != null) text += " (" + humanRep + ")"; } else { text = String.valueOf(value); } return super.getListCellRendererComponent(list, text, index, isSelected, cellHasFocus); } }); JComboBox dst = new JComboBox(new Object[] { "File", "Clipboard" }); Object[] msg = { "Source:", doc.getTitle(), "Export as:", src, "Export to:", dst }; Object[] options = { "Ok", "Cancel" }; JOptionPane op = new JOptionPane(msg, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, options); JDialog dialog = op.createDialog(getWindow(), title); dialog.setModal(true); dialog.setVisible(true); boolean ok = "Ok".equals(op.getValue()); DataFlavor flavor = (DataFlavor) src.getSelectedItem(); dialog.dispose(); if (!ok) return; if (flavor == null) return; if ("Clipboard".equals(dst.getSelectedItem())) { Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard(); cb.setContents(new SelectedTransfer(flavor, transferable), null); } else { export(transferable, flavor); } }
From source file:com.raceup.fsae.test.TesterGui.java
/** * Shows dialog with info about unsuccessful test submission *///w ww .ja v a 2 s .c o m private void showUnSuccessfulTestSubmissionDialog() { totalTestTimer.start(); // re-start total timer String message = test.toString(); message += "\nDon't worry, be happy: this box will automatically " + "close after " + Integer.toString(SECONDS_WAIT_BETWEEN_SUBMISSIONS) + " seconds of your " + "submission.\nEnjoy."; JOptionPane opt = new JOptionPane(message, JOptionPane.WARNING_MESSAGE, JOptionPane.DEFAULT_OPTION, null, new Object[] {}); // no buttons final JDialog dlg = opt.createDialog("Error"); new Thread(() -> { try { Thread.sleep(SECONDS_WAIT_BETWEEN_SUBMISSIONS * 1000); dlg.dispose(); } catch (Throwable t) { System.err.println(t.toString()); } }).start(); dlg.setVisible(true); }
From source file:com.floreantpos.config.ui.TerminalConfigurationView.java
public void restartPOS() { JOptionPane optionPane = new JOptionPane(Messages.getString("TerminalConfigurationView.26"), //$NON-NLS-1$ JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, Application.getApplicationIcon(), new String[] { /*Messages.getString("TerminalConfigurationView.28"),*/Messages .getString("TerminalConfigurationView.30") }); //$NON-NLS-1$ //$NON-NLS-2$ Object[] optionValues = optionPane.getComponents(); for (Object object : optionValues) { if (object instanceof JPanel) { JPanel panel = (JPanel) object; Component[] components = panel.getComponents(); for (Component component : components) { if (component instanceof JButton) { component.setPreferredSize(new Dimension(100, 80)); JButton button = (JButton) component; button.setPreferredSize(PosUIManager.getSize(100, 50)); }/*from w w w . j a v a 2s .com*/ } } } JDialog dialog = optionPane.createDialog(Application.getPosWindow(), Messages.getString("TerminalConfigurationView.31")); //$NON-NLS-1$ dialog.setIconImage(Application.getApplicationIcon().getImage()); dialog.setLocationRelativeTo(Application.getPosWindow()); dialog.setVisible(true); Object selectedValue = (String) optionPane.getValue(); if (selectedValue != null) { if (selectedValue.equals(Messages.getString("TerminalConfigurationView.28"))) { //$NON-NLS-1$ try { Main.restart(); } catch (IOException | InterruptedException | URISyntaxException e) { } } else { } } }
From source file:Installer.java
public void run() { JOptionPane optionPane = new JOptionPane(this, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, new String[] { "Install", "Cancel" }); emptyFrame = new Frame("Vivecraft Installer"); emptyFrame.setUndecorated(true);//from ww w . j a v a 2 s .c o m emptyFrame.setVisible(true); emptyFrame.setLocationRelativeTo(null); dialog = optionPane.createDialog(emptyFrame, "Vivecraft Installer"); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setVisible(true); String str = ((String) optionPane.getValue()); if (str != null && ((String) optionPane.getValue()).equalsIgnoreCase("Install")) { int option = JOptionPane.showOptionDialog(null, "Please ensure you have closed the Minecraft launcher before proceeding.\n" //"Also, if installing with Forge please ensure you have installed Forge " + FORGE_VERSION + " first.", , "Important!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, null, null); if (option == JOptionPane.OK_OPTION) { monitor = new ProgressMonitor(null, "Installing Vivecraft...", "", 0, 100); monitor.setMillisToDecideToPopup(0); monitor.setMillisToPopup(0); task = new InstallTask(); task.addPropertyChangeListener(this); task.execute(); } else { dialog.dispose(); emptyFrame.dispose(); } } else { dialog.dispose(); emptyFrame.dispose(); } }
From source file:org.objectstyle.cayenne.modeler.editor.ObjEntityTab.java
void setEntityName(String newName) { if (newName != null && newName.trim().length() == 0) { newName = null;/*from www .j a v a 2 s . com*/ } ObjEntity entity = mediator.getCurrentObjEntity(); if (entity == null) { return; } if (Util.nullSafeEquals(newName, entity.getName())) { return; } if (newName == null) { throw new ValidationException("Entity name is required."); } else if (entity.getDataMap().getObjEntity(newName) == null) { // completely new name, set new name for entity EntityEvent e = new EntityEvent(this, entity, entity.getName()); ProjectUtil.setObjEntityName(entity.getDataMap(), entity, newName); mediator.fireObjEntityEvent(e); // suggest to update class name String suggestedClassName = suggestedClassName(entity); if (suggestedClassName != null && !suggestedClassName.equals(entity.getClassName())) { JOptionPane pane = new JOptionPane( new Object[] { "Change class name to match new entity name?", "Suggested class name: " + suggestedClassName }, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, new Object[] { "Change", "Cancel" }); pane.createDialog(Application.getFrame(), "Update Class Name").show(); if ("Change".equals(pane.getValue())) { className.setText(suggestedClassName); setClassName(suggestedClassName); } } } else { // there is an entity with the same name throw new ValidationException("There is another entity with name '" + newName + "'."); } }