Java Code Examples for javax.swing.JOptionPane#getValue()
The following examples show how to use
javax.swing.JOptionPane#getValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OurDialog.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** * Helper method for constructing an always-on-top modal dialog. */ private static Object show(JFrame parent, String title, int type, Object message, Object[] options, Object initialOption) { if (options == null) { options = new Object[] { "Ok" }; initialOption = "Ok"; } JOptionPane p = new JOptionPane(message, type, JOptionPane.DEFAULT_OPTION, null, options, initialOption); p.setInitialValue(initialOption); JDialog d = p.createDialog(parent, title); p.selectInitialValue(); d.setAlwaysOnTop(true); d.setVisible(true); d.dispose(); return p.getValue(); }
Example 2
Source File: DialogInputReader.java From obevo with Apache License 2.0 | 5 votes |
@Override public String readLine(String promptMessage) { final JTextField juf = new JTextField(); JOptionPane juop = new JOptionPane(juf, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION); JDialog userDialog = juop.createDialog(promptMessage); userDialog.addComponentListener(new ComponentAdapter() { @Override public void componentShown(ComponentEvent e) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { juf.requestFocusInWindow(); } }); } }); userDialog.setVisible(true); int uresult = (Integer) juop.getValue(); userDialog.dispose(); String userName = null; if (uresult == JOptionPane.OK_OPTION) { userName = new String(juf.getText()); } if (StringUtils.isEmpty(userName)) { return null; } else { return userName; } }
Example 3
Source File: DialogInputReader.java From obevo with Apache License 2.0 | 5 votes |
@Override public String readPassword(String promptMessage) { final JPasswordField jpf = new JPasswordField(); JOptionPane jop = new JOptionPane(jpf, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION); JDialog dialog = jop.createDialog(promptMessage); dialog.addComponentListener(new ComponentAdapter() { @Override public void componentShown(ComponentEvent e) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { jpf.requestFocusInWindow(); } }); } }); dialog.setVisible(true); int result = (Integer) jop.getValue(); dialog.dispose(); String password = null; if (result == JOptionPane.OK_OPTION) { password = new String(jpf.getPassword()); } if (StringUtils.isEmpty(password)) { return null; } else { return password; } }
Example 4
Source File: OptionDialog.java From Astrosoft with GNU General Public License v2.0 | 5 votes |
public static int showDialog(String message, int messageType){ int optionType = JOptionPane.DEFAULT_OPTION; String title = null; if (messageType == JOptionPane.ERROR_MESSAGE){ title = "Error "; optionType = JOptionPane.DEFAULT_OPTION; }else if (messageType == JOptionPane.QUESTION_MESSAGE){ title = "Confirm "; optionType = JOptionPane.YES_NO_OPTION; } else if (messageType == JOptionPane.INFORMATION_MESSAGE){ title = "Information "; optionType = JOptionPane.DEFAULT_OPTION; } JOptionPane pane = new JOptionPane(message, messageType, optionType); JDialog dialog = pane.createDialog(pane, title); UIUtil.applyOptionPaneBackground(pane,UIConsts.OPTIONPANE_BACKGROUND); dialog.setVisible(true); Object selectedValue = pane.getValue(); if(selectedValue instanceof Integer) { return ((Integer)selectedValue).intValue(); } return JOptionPane.CLOSED_OPTION; }
Example 5
Source File: ModelessOptionPane.java From audiveris with GNU Affero General Public License v3.0 | 5 votes |
private static int optionOf (JOptionPane pane) { Object selectedValue = pane.getValue(); if (selectedValue == null) { return JOptionPane.CLOSED_OPTION; } else if (selectedValue instanceof Integer) { return ((Integer) selectedValue); } else { return JOptionPane.CLOSED_OPTION; } }
Example 6
Source File: GUIInputHandler.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
@Override public String inputPassword(String messageText) { final JPasswordField passwordField = new JPasswordField(); JOptionPane jop = new JOptionPane(new Object[] { messageText, passwordField }, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION); JDialog dialog = jop.createDialog("Authentication required"); dialog.addComponentListener(new ComponentAdapter() { @Override public void componentShown(ComponentEvent e) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { passwordField.requestFocusInWindow(); passwordField.requestFocus(); } }); } }); dialog.setVisible(true); int result = (Integer) jop.getValue(); if (result == JOptionPane.OK_OPTION) { return new String(passwordField.getPassword()); } else { return null; } }
Example 7
Source File: Messages.java From jclic with GNU General Public License v2.0 | 5 votes |
protected int getFeedback(Component parent, JOptionPane pane, String title) { int result = CANCEL; if (showDlg(parent, pane, title)) { Object selectedValue = pane.getValue(); if (selectedValue != null) { for (int i = 0; i < NUM_BUTTONS; i++) { if (dlgButtons[i].equals(selectedValue)) { result = i; break; } } } } return result; }
Example 8
Source File: LoneOptionDialog.java From stendhal with GNU General Public License v2.0 | 5 votes |
/** * Show a confirmation dialog with specified, selectable message. * * @param message message string * @param title window title * @param optionType type of option, These are specified in JOptionDialog * @param messageType type of message, These are specified in JOptionDialog * * @return integer indicating the option selected by the user */ static int showConfirmDialog(String message, String title, int optionType, int messageType) { JOptionPane pane = new JOptionPane(new SelectableLabel(message), messageType, optionType); JDialog dialog = pane.createDialog(title); dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); setLocation(dialog); dialog.setVisible(true); dialog.dispose(); Object selectedValue = pane.getValue(); if (selectedValue == null) { return JOptionPane.CLOSED_OPTION; } Object[] options = pane.getOptions(); if (options == null) { if (selectedValue instanceof Integer) { return (Integer) selectedValue; } return JOptionPane.CLOSED_OPTION; } for (int i = 0; i < options.length; i++) { if (options[i].equals(selectedValue)) { return i; } } return JOptionPane.CLOSED_OPTION; }
Example 9
Source File: TaskYesNoAllDialog.java From wpcleaner with Apache License 2.0 | 5 votes |
/** * @see java.lang.Runnable#run() */ @Override public void run() { Object[] options = new Object[] { GT._T("Yes"), GT._T("Yes to all"), GT._T("No"), GT._T("No to all"), }; JOptionPane pane = new JOptionPane( message, JOptionPane.WARNING_MESSAGE, JOptionPane.YES_NO_OPTION, null, options); JDialog dialog = pane.createDialog(parent, Version.PROGRAM); dialog.setVisible(true); Object selectedValue = pane.getValue(); if (selectedValue == null) { result = JOptionPane.CLOSED_OPTION; } else if (options[0].equals(selectedValue)) { result = JOptionPane.YES_OPTION; } else if (options[1].equals(selectedValue)) { result = Utilities.YES_ALL_OPTION; } else if (options[2].equals(selectedValue)) { result = JOptionPane.NO_OPTION; } else if (options[3].equals(selectedValue)) { result = Utilities.NO_ALL_OPTION; } else { result = JOptionPane.CLOSED_OPTION; } }
Example 10
Source File: ModelessOptionPane.java From libreveris with GNU Lesser General Public License v3.0 | 5 votes |
private static int optionOf (JOptionPane pane) { Object selectedValue = pane.getValue(); if (selectedValue == null) { return JOptionPane.CLOSED_OPTION; } else if (selectedValue instanceof Integer) { return ((Integer) selectedValue).intValue(); } else { return JOptionPane.CLOSED_OPTION; } }
Example 11
Source File: BytecodeViewer.java From bytecode-viewer with GNU General Public License v3.0 | 5 votes |
/** * Resets the workspace with optional user input required * * @param ask if should require user input or not */ public static void resetWorkSpace(boolean ask) { if(ask) { JOptionPane pane = new JOptionPane( "Are you sure you want to reset the workspace?\n\rIt will also reset your file navigator and search."); Object[] options = new String[]{"Yes", "No"}; pane.setOptions(options); JDialog dialog = pane.createDialog(viewer, "Bytecode Viewer - Reset Workspace"); dialog.setVisible(true); Object obj = pane.getValue(); int result = -1; for (int k = 0; k < options.length; k++) if (options[k].equals(obj)) result = k; if (result != 0) return; } files.clear(); LazyNameUtil.reset(); MainViewerGUI.getComponent(FileNavigationPane.class).resetWorkspace(); MainViewerGUI.getComponent(WorkPane.class).resetWorkspace(); MainViewerGUI.getComponent(SearchingPane.class).resetWorkspace(); the.bytecode.club.bytecodeviewer.api.BytecodeViewer.getClassNodeLoader().clear(); }
Example 12
Source File: VCardEditor.java From Spark with Apache License 2.0 | 4 votes |
/** * Displays a users profile. * * @param jid * the jid of the user. * @param vcard * the users vcard. * @param parent * the parent component, used for location handling. */ public void displayProfile(final BareJid jid, VCard vcard, JComponent parent) { VCardViewer viewer = new VCardViewer(jid); final JFrame dlg = new JFrame(Res.getString("title.view.profile.for", jid)); avatarLabel = new JLabel(); avatarLabel.setHorizontalAlignment(JButton.RIGHT); avatarLabel.setBorder(BorderFactory.createBevelBorder(0, Color.white, Color.lightGray)); // The user should only be able to close this dialog. Object[] options = { Res.getString("button.view.profile"), Res.getString("close") }; final JOptionPane pane = new JOptionPane(viewer, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, options, options[0]); // mainPanel.add(pane, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, // GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 5, // 5, 5), 0, 0)); dlg.setIconImage(SparkRes.getImageIcon(SparkRes.PROFILE_IMAGE_16x16) .getImage()); dlg.pack(); dlg.setSize(350, 250); dlg.setResizable(true); dlg.setContentPane(pane); dlg.setLocationRelativeTo(parent); PropertyChangeListener changeListener = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent e) { if (pane.getValue() instanceof Integer) { pane.removePropertyChangeListener(this); dlg.dispose(); return; } String value = (String) pane.getValue(); if (Res.getString("close").equals(value)) { pane.removePropertyChangeListener(this); dlg.dispose(); } else if (Res.getString("button.view.profile").equals(value)) { pane.setValue(JOptionPane.UNINITIALIZED_VALUE); SparkManager.getVCardManager().viewFullProfile(jid, pane); } } }; pane.addPropertyChangeListener(changeListener); dlg.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent keyEvent) { if (keyEvent.getKeyChar() == KeyEvent.VK_ESCAPE) { dlg.dispose(); } } }); dlg.setVisible(true); dlg.toFront(); dlg.requestFocus(); }
Example 13
Source File: UsernamePassword.java From OpenDA with GNU Lesser General Public License v3.0 | 4 votes |
/** * Ask using a GUI for the username and password. */ private void readFromGUI() { // Create fields for user name. final JTextField usernameField = new JTextField(20); usernameField.setText(this.username); final JLabel usernameLabel = new JLabel("Username: "); usernameLabel.setLabelFor(usernameField); final JPanel usernamePane = new JPanel(new FlowLayout(FlowLayout.TRAILING)); usernamePane.add(usernameLabel); usernamePane.add(usernameField); // Create fields for password. final JPasswordField passwordField = new JPasswordField(20); passwordField.setText(this.password); final JLabel passwordLabel = new JLabel("Password: "); passwordLabel.setLabelFor(passwordField); final JPanel passwordPane = new JPanel(new FlowLayout(FlowLayout.TRAILING)); passwordPane.add(passwordLabel); passwordPane.add(passwordField); // Create panel final JPanel main = new JPanel(); main.setLayout(new BoxLayout(main, BoxLayout.PAGE_AXIS)); main.add(usernamePane); main.add(passwordPane); // Create and handle dialog final JOptionPane jop = new JOptionPane(main, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION); final JDialog dialog = jop.createDialog("User name and password"); dialog.addComponentListener(new ComponentAdapter() { public void componentShown(ComponentEvent e) { SwingUtilities.invokeLater(new Runnable() { public void run() { if (usernameField.getText().isEmpty()) { usernameField.requestFocusInWindow(); } else { passwordField.requestFocusInWindow(); } } }); } }); dialog.setVisible(true); final Integer result = (Integer) jop.getValue(); dialog.dispose(); if (result.intValue() == JOptionPane.OK_OPTION) { this.username = usernameField.getText(); final char[] pwd = passwordField.getPassword(); this.password = new String(pwd); } }
Example 14
Source File: ZStringArrayDecrypter.java From bytecode-viewer with GNU General Public License v3.0 | 4 votes |
@Override public void execute(ArrayList<ClassNode> classNodeList) { JOptionPane pane = new JOptionPane( "WARNING: This will load the classes into the JVM and execute the initialize function" + BytecodeViewer.nl + "for each class. IF THE FILE YOU'RE LOADING IS MALICIOUS, DO NOT CONTINUE." ); Object[] options = new String[]{"Continue", "Cancel"}; pane.setOptions(options); JDialog dialog = pane.createDialog(BytecodeViewer.viewer, "Bytecode Viewer - WARNING"); dialog.setVisible(true); Object obj = pane.getValue(); int result = -1; for (int k = 0; k < options.length; k++) if (options[k].equals(obj)) result = k; if (result == 0) { boolean needsWarning = false; for (Class<?> debug : the.bytecode.club.bytecodeviewer.api.BytecodeViewer.loadClassesIntoClassLoader()) { try { Field[] fields = debug.getDeclaredFields(); for (Field field : fields) { if (field.getName().equals("z")) { out.append(debug.getName() + ":" + BytecodeViewer.nl); field.setAccessible(true); if (field.get(null) != null && field.get(null) instanceof String[] && Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers())) { String[] fieldVal = (String[]) field.get(null); for (int i = 0; i < fieldVal.length; i++) { out.append(" z[" + i + "] = " + fieldVal[i] + BytecodeViewer.nl); } } } } } catch (NoClassDefFoundError | Exception e) { System.err.println("Failed loading class " + debug.getName()); e.printStackTrace(); needsWarning = true; } } if (needsWarning) { BytecodeViewer.showMessage("Some classes failed to decrypt, if you'd like to decrypt all of them" + BytecodeViewer.nl + "makes sure you include ALL the libraries it requires."); } gui.setText(out.toString()); gui.setVisible(true); } }
Example 15
Source File: Macronizer.java From tn5250j with GNU General Public License v2.0 | 4 votes |
public static void showRunScriptDialog(SessionPanel session) { JPanel rsp = new JPanel(); rsp.setLayout(new BorderLayout()); JLabel jl = new JLabel("Enter script to run"); final JTextField rst = new JTextField(); rsp.add(jl,BorderLayout.NORTH); rsp.add(rst,BorderLayout.CENTER); Object[] message = new Object[1]; message[0] = rsp; String[] options = {"Run","Cancel"}; final JOptionPane pane = new JOptionPane( message, // the dialog message array JOptionPane.QUESTION_MESSAGE, // message type JOptionPane.DEFAULT_OPTION, // option type null, // optional icon, use null to use the default icon options, // options string array, will be made into buttons// options[0]); // option that should be made into a default button // create a dialog wrapping the pane final JDialog dialog = pane.createDialog(session, // parent frame "Run Script" // dialog title ); // add the listener that will set the focus to // the desired option dialog.addWindowListener( new WindowAdapter() { public void windowOpened( WindowEvent e) { super.windowOpened( e ); // now we're setting the focus to the desired component // it's not the best solution as it depends on internals // of the OptionPane class, but you can use it temporarily // until the bug gets fixed // also you might want to iterate here thru the set of // the buttons and pick one to call requestFocus() for it rst.requestFocus(); } }); dialog.setVisible(true); // now we can process the value selected // now we can process the value selected // if its Integer, the user most likely hit escape Object myValue = pane.getValue(); if (!(myValue instanceof Integer)) { String value = (String) myValue; if (value.equals(options[0])) { // send option along with system request if (rst.getText().length() > 0) { invoke(rst.getText(), session); } } } }
Example 16
Source File: Desktop.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
void doConnect() { final String[] options = new String[Activator.remoteHosts.size()]; Activator.remoteHosts.copyInto(options); // The selection comp I want in the dialog final JComboBox combo = new JComboBox(options); combo.setEditable(true); // Mindboggling complicate way of creating an option dialog // without the auto-generated input field final JLabel msg = new JLabel(Strings.get("remote_connect_msg")); final JPanel panel = new JPanel(new BorderLayout()); panel.add(combo, BorderLayout.SOUTH); panel.add(msg, BorderLayout.NORTH); final JOptionPane optionPane = new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE); optionPane.setIcon(connectIconLarge); optionPane.setOptionType(JOptionPane.OK_CANCEL_OPTION); optionPane.setWantsInput(false); optionPane.setOptions(new String[] { Strings.get("ok"), Strings.get("cancel"), Strings.get("local"), }); optionPane.selectInitialValue(); final JDialog dialog = optionPane.createDialog(frame, Strings.get("remote_connect_title")); dialog.setVisible(true); dialog.dispose(); if (!(optionPane.getValue() instanceof String)) { // We'll get an Integer if // the user pressed Esc return; } final String value = (String) optionPane.getValue(); if (Strings.get("cancel").equals(value)) { return; } String s = (String) combo.getSelectedItem(); if (Strings.get("local").equals(value)) { s = ""; } if (!Activator.remoteHosts.contains(s)) { Activator.remoteHosts.addElement(s); } if ((s != null)) { Activator.openRemote(s); } }
Example 17
Source File: WindowUtils.java From gcs with Mozilla Public License 2.0 | 4 votes |
/** * Shows an option dialog. * * @param parentComponent The parent {@link Component} to use. May be {@code null}. * @param message The message. May be a {@link Component}. * @param title The title to use. * @param resizable Whether to allow the dialog to be resized by the user. * @param optionType The type of option dialog. Use the {@link JOptionPane} constants. * @param messageType The type of message. Use the {@link JOptionPane} constants. * @param icon The icon to use. May be {@code null}. * @param options The options to display. May be {@code null}. * @param initialValue The initial option. * @return See the documentation for {@link JOptionPane}. */ public static int showOptionDialog(Component parentComponent, Object message, String title, boolean resizable, int optionType, int messageType, Icon icon, Object[] options, Object initialValue) { JOptionPane pane = new JOptionPane(message, messageType, optionType, icon, options, initialValue); pane.setUI(new SizeAwareBasicOptionPaneUI(pane.getUI())); pane.setInitialValue(initialValue); pane.setComponentOrientation((parentComponent == null ? JOptionPane.getRootFrame() : parentComponent).getComponentOrientation()); JDialog dialog = pane.createDialog(getWindowForComponent(parentComponent), title); WindowSizeEnforcer.monitor(dialog); pane.selectInitialValue(); dialog.setResizable(resizable); Component field = getFirstFocusableField(message); if (field != null) { dialog.addWindowFocusListener(new WindowAdapter() { @Override public void windowGainedFocus(WindowEvent event) { field.requestFocus(); dialog.removeWindowFocusListener(this); } }); } dialog.setVisible(true); dialog.dispose(); pane.setMessage(null); Object selectedValue = pane.getValue(); if (selectedValue != null) { if (options == null) { if (selectedValue instanceof Integer) { return ((Integer) selectedValue).intValue(); } } else { int length = options.length; for (int i = 0; i < length; i++) { if (options[i].equals(selectedValue)) { return i; } } } } return JOptionPane.CLOSED_OPTION; }
Example 18
Source File: BookmarkEditor.java From FancyBing with GNU General Public License v3.0 | 4 votes |
public Bookmark editItem(Component parent, String title, Bookmark bookmark, boolean selectName, MessageDialogs messageDialogs) { JPanel panel = new JPanel(new BorderLayout(GuiUtil.SMALL_PAD, 0)); m_panelLeft = new JPanel(new GridLayout(0, 1, 0, GuiUtil.PAD)); panel.add(m_panelLeft, BorderLayout.WEST); m_panelRight = new JPanel(new GridLayout(0, 1, 0, GuiUtil.PAD)); panel.add(m_panelRight, BorderLayout.CENTER); m_name = createEntry("LB_BOOKMARKEDITOR_NAME", 25, bookmark.m_name); String file = ""; if (bookmark.m_file != null) file = bookmark.m_file.toString(); m_file = createEntry("LB_BOOKMARKEDITOR_FILE", 25, file); String move = ""; if (bookmark.m_move > 0) move = Integer.toString(bookmark.m_move); m_move = createEntry("LB_BOOKMARKEDITOR_MOVE", 10, move); m_variation = createEntry("LB_BOOKMARKEDITOR_VARIATION", 10, bookmark.m_variation); JOptionPane optionPane = new JOptionPane(panel, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION); JDialog dialog = optionPane.createDialog(parent, title); boolean done = false; while (! done) { if (selectName) m_name.selectAll(); dialog.addWindowListener(new WindowAdapter() { public void windowActivated(WindowEvent e) { m_name.requestFocusInWindow(); } }); dialog.setVisible(true); Object value = optionPane.getValue(); if (! (value instanceof Integer) || ((Integer)value).intValue() != JOptionPane.OK_OPTION) return null; done = validate(parent, messageDialogs); } String newName = m_name.getText().trim(); File newFile = new File(m_file.getText()); int newMove = getMove(); String newVariation = m_variation.getText().trim(); Bookmark newBookmark = new Bookmark(newName, newFile, newMove, newVariation); dialog.dispose(); return newBookmark; }