Java 8 JOptionPane - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 JOptionPane class.

This code example shows how to use the following methods:createDialog, setOptions
    } 
 
    void showGUI(Properties fileProps) {
        Properties guiProps = new Properties(fileProps);
        JOptionPane p = createPane(guiProps);
        p.createDialog("Select Tool").setVisible(true);
 
        toolName = (String) toolChoice.getSelectedItem();
        toolArgs = argsField.getText();
 
        if (defaultCheck.isSelected()) {
            if (toolName.equals("")) {
                fileProps.remove("tool.name");
            } else { 
                fileProps.put("tool.name", toolName);
                fileProps.put(toolName + ".args", toolArgs);
            } 
            writeProperties(propertyFile, fileProps);
        } 
    } 

6
CodeRank
This code example shows how to use the following methods:addPropertyChangeListener, getValue
                + "Are you sure to continue ?\n\n"; 
        JCheckBox checkbox = new JCheckBox("Do not show this dialog again.");
 
        Object[] params = { message, checkbox }; 
 
        final JOptionPane optionPane = new JOptionPane(
                params, 
                JOptionPane.WARNING_MESSAGE,
                JOptionPane.YES_NO_OPTION);
 
        final JDialog dialog = new JDialog(getMainFrame(), "Confirmation of licenses and agreements", true);
        dialog.setContentPane(optionPane);
        dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
        optionPane.addPropertyChangeListener(
                new PropertyChangeListener() {
                    @Override 
                    public void propertyChange(PropertyChangeEvent e) {
                        String prop = e.getPropertyName();
 
                        if (dialog.isVisible()

7
CodeRank
This code example shows how to use the following methods:isEnabled, isShowing, isVisible, getClass, getMessage
  @RunsInCurrentThread 
  @Override 
  protected @Nonnull String doFormat(@Nonnull Component c) {
    JOptionPane optionPane = (JOptionPane)c;
    String format = "%s[message=%s, messageType=%s, optionType=%s, enabled=%b, visible=%b, showing=%b]";
    return String.format(format, optionPane.getClass().getName(), quote(optionPane.getMessage()),
        MESSAGE_TYPES.get(optionPane.getMessageType()), OPTION_TYPES.get(optionPane.getOptionType()),
        optionPane.isEnabled(), optionPane.isVisible(), optionPane.isShowing());
  } 
 
  /** 
   * @return {@code JOptionPane.class}. 
   */ 
  @Override 
  public @Nonnull Class<? extends Component> targetType() {
    return JOptionPane.class;
  } 
} 
7
CodeRank
This code example shows how to use the following methods:createDialog, setOptions
	 
	public boolean showGUI(String contextType) {
		this.timer.setActionCommand("timeout");
		/*JOptionPane optionPane = new JOptionPane("Eggs are not supposed to be green.", 
				JOptionPane.INFORMATION_MESSAGE);*/ 
		JOptionPane optionPane = new JOptionPane(
			    "Implementing Effect: PERMIT\n" 
			    + "for resource:"+contextType+"\n"
			    + "Click Cancel to Abort", 
			    JOptionPane.QUESTION_MESSAGE,
			    JOptionPane.YES_NO_OPTION);
		 
		JButton cancelBtn = new JButton("Cancel");
		cancelBtn.addActionListener(this);
		cancelBtn.setActionCommand("cancelled");
		optionPane.setOptions(new Object[]{cancelBtn});
		dialog = optionPane.createDialog("Privacy Preference Evaluation");
		 
		timer.start();
		dialog.setVisible(true);

5
CodeRank
This code example shows how to use the following methods:createDialog, getValue
     * @return true if the file should be overwritten; else otherwise 
     */ 
    private boolean showConfirmOverwriteDialog() { 
        String message = MessageFormat.format(l10n.getString("ConfirmingFileChooser.sure_to_replace"),
                getSelectedFile().getName(), getSelectedFile().getParent());
        JOptionPane pane = new JOptionPane(message, JOptionPane.QUESTION_MESSAGE,
                JOptionPane.DEFAULT_OPTION, null, options, overwriteOption);
         
        JDialog confirmDialog = pane.createDialog(getParent(), null);
        RuntimeUtils.setDocumentModalDialog(confirmDialog);
        confirmDialog.setResizable(true);
        confirmDialog.pack();
 
        confirmDialog.setVisible(true);
        confirmDialog.dispose();
 
        Object value = pane.getValue();
        return overwriteOption.equals(value);
    } 
     

5
CodeRank
This code example shows how to use the following methods:createDialog, getValue
    private boolean isStartConfirmed() { 
        // Unfortunately the systray gives no hint where it is located, so we have to guess 
        // by getting the current mouse location. 
        final Point currentMousePosition = MouseInfo.getPointerInfo().getLocation();
 
        final JOptionPane pane = new JOptionPane(
                textBundle.textFor("StartActivityConfirmDialog.Message"), //$NON-NLS-1$
                JOptionPane.QUESTION_MESSAGE, 
                JOptionPane.YES_NO_OPTION
        ); 
 
        final JDialog dialog = pane.createDialog(textBundle.textFor("StartActivityConfirmDialog.Title")); //$NON-NLS-1$
        dialog.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/Baralga-Tray.gif"))); //$NON-NLS-1$ 
         
        Dimension d = dialog.getPreferredSize();
        final Point preferredLeftTop = new Point(currentMousePosition.x - d.width / 2, currentMousePosition.y - d.height / 2);
        AWTUtils.keepInScreenBounds(preferredLeftTop, dialog);
 
        dialog.setVisible(true);
        dialog.dispose();

5
CodeRank
This code example shows how to use the following methods:addPropertyChangeListener
        contentPane.setLayout(new BorderLayout());
        contentPane.add(pane, BorderLayout.CENTER);
        dialog.setResizable(false);
        dialog.pack();
        dialog.setLocationRelativeTo(null);
        WindowAdapter adapter = new WindowAdapter() {
 
            private boolean gotFocus = false;
 
            @Override 
            public void windowClosing(WindowEvent we) {
                pane.setValue(null);
            } 
 
            @Override 
            public void windowGainedFocus(WindowEvent we) {
                // Once window gets focus, set initial focus 
                if (!gotFocus) {
                    pane.selectInitialValue();
                    gotFocus = true;

5
CodeRank
This code example shows how to use the following methods:addPropertyChangeListener
        //Create an array specifying the number of dialog buttons 
        //and their text. 
        Object[] options = {"OK"}; 
 
        //Create the JOptionPane. 
        final JOptionPane optionPane = new JOptionPane(array,
                                    JOptionPane.QUESTION_MESSAGE,
                                    JOptionPane.OK_OPTION,
                                    null, 
                                    options, 
                                    options[0]); 
 
//        final JOptionPane optionPane = new JOptionPane("The only way to close this dialog is by\n" 
//                        + "pressing one of the following buttons.\n" + "Do you understand?", 
//            JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION); 
 
 
        final JDialog dialog = new JDialog(frame, "Enter Description", true);
        DialogClosingThread closer = new DialogClosingThread(dialog);
        closer.observe(textField);

5
CodeRank
This code example shows how to use the following methods:createDialog
 
    /** 
     * Displays an error message. 
     */ 
    public void displayError(String message) {
        JOptionPane pane = new JOptionPane(message, JOptionPane.ERROR_MESSAGE);
        JDialog dialog = pane.createDialog(parentComponent, "ERROR");
        dialog.setModal(false);
        dialog.setVisible(true);
    } 
 
    /** 
     * Displays an error resulting from the specified Exception. 
     */ 
    public void displayError(Exception ex) {
        JErrorPane pane = new JErrorPane(ex, JOptionPane.ERROR_MESSAGE);
        JDialog dialog = pane.createDialog(parentComponent, "ERROR");
        dialog.setModal(false);
        dialog.setVisible(true);
    } 
5
CodeRank
This code example shows how to use the following methods:isShowing
      super(JOptionPane.class);
    } 
 
    @Override 
    protected boolean isMatching(@Nonnull JOptionPane optionPane) {
      return optionPane.isShowing();
    } 
  } 
} 
4
CodeRank
See Code Examples for Java 8 JOptionPane Methods: