當前位置: 首頁>>代碼示例>>Java>>正文


Java JOptionPane.OK_CANCEL_OPTION屬性代碼示例

本文整理匯總了Java中javax.swing.JOptionPane.OK_CANCEL_OPTION屬性的典型用法代碼示例。如果您正苦於以下問題:Java JOptionPane.OK_CANCEL_OPTION屬性的具體用法?Java JOptionPane.OK_CANCEL_OPTION怎麽用?Java JOptionPane.OK_CANCEL_OPTION使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在javax.swing.JOptionPane的用法示例。


在下文中一共展示了JOptionPane.OK_CANCEL_OPTION屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: actionPerformed

public void actionPerformed(ActionEvent e) {
    if (!isEnabled())
        return;

    TermOptions clonedTermOptions = termOptions.makeCopy();
    TermOptionsPanel subPanel = new TermOptionsPanel();
    subPanel.setTermOptions(clonedTermOptions);

    JOptionPane optionPane = new JOptionPane(subPanel,
                                             JOptionPane.PLAIN_MESSAGE,
                                             JOptionPane.OK_CANCEL_OPTION
                                             );
        JDialog dialog = optionPane.createDialog(Terminal.this,
                                                 "NBTerm Options");
        dialog.setVisible(true);      // WILL BLOCK!

        if (optionPane.getValue() == null)
            return;     // was closed at the window level

        switch ((Integer) optionPane.getValue()) {
            case JOptionPane.OK_OPTION:
                System.out.printf("Dialog returned OK\n");
                termOptions.assign(clonedTermOptions);
                applyTermOptions(false);
                termOptions.storeTo(prefs);
                break;
            case JOptionPane.CANCEL_OPTION:
                System.out.printf("Dialog returned CANCEL\n");
                break;
            case JOptionPane.CLOSED_OPTION:
                System.out.printf("Dialog returned CLOSED\n");
                break;
            default:
                System.out.printf("Dialog returned OTHER: %s\n",
                                  optionPane.getValue());
                break;
        }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:38,代碼來源:Terminal.java

示例2: createDialog

/**
 * Creates and returns a fresh dialog for the given frame.
 */
private JDialog createDialog(Component frame) {
    Object[] buttons = new Object[] {getOkButton(), getCancelButton()};
    JPanel input = new JPanel();
    input.setLayout(new BorderLayout());
    input.add(getChoiceBox(), BorderLayout.NORTH);
    // add an error label if there is a parser
    if (this.parsed) {
        JPanel errorPanel = new JPanel(new BorderLayout());
        errorPanel.add(getErrorLabel());
        input.add(errorPanel, BorderLayout.SOUTH);
    }
    JPanel main = new JPanel();
    main.setLayout(new BorderLayout());
    main.add(input, BorderLayout.CENTER);
    if (this.parsed) {
        main.add(createSyntaxPanel(), BorderLayout.EAST);
    }
    JOptionPane panel = new JOptionPane(main, JOptionPane.PLAIN_MESSAGE,
        JOptionPane.OK_CANCEL_OPTION, null, buttons);
    JDialog result = panel.createDialog(frame, this.title);
    result.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    result.addWindowListener(this.closeListener);
    return result;
}
 
開發者ID:meteoorkip,項目名稱:JavaGraph,代碼行數:27,代碼來源:FormulaDialog.java

示例3: getOptionPane

/**
 * Lazily creates and returns the option pane that is to form the content of
 * the dialog.
 */
private JOptionPane getOptionPane() {
    if (this.optionPane == null) {
        JLabel oldLabel = new JLabel(OLD_TEXT);
        JLabel newLabel = new JLabel(NEW_TEXT);
        oldLabel.setPreferredSize(newLabel.getPreferredSize());
        JPanel oldPanel = new JPanel(new BorderLayout());
        oldPanel.add(oldLabel, BorderLayout.WEST);
        oldPanel.add(getOldField(), BorderLayout.CENTER);
        oldPanel.add(getOldTypeLabel(), BorderLayout.EAST);
        JPanel newPanel = new JPanel(new BorderLayout());
        newPanel.add(newLabel, BorderLayout.WEST);
        newPanel.add(getNewField(), BorderLayout.CENTER);
        newPanel.add(getNewTypeCombobox(), BorderLayout.EAST);
        JPanel errorPanel = new JPanel(new BorderLayout());
        errorPanel.add(getErrorLabel());
        errorPanel.setPreferredSize(oldPanel.getPreferredSize());
        this.optionPane = new JOptionPane(new Object[] {oldPanel, newPanel, errorPanel},
            JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null,
            new Object[] {getFindButton(), getReplaceButton(), getCancelButton()});
    }
    return this.optionPane;
}
 
開發者ID:meteoorkip,項目名稱:JavaGraph,代碼行數:26,代碼來源:FindReplaceDialog.java

示例4: createDialog

/**
 * Creates and returns a fresh dialog for the given frame.
 */
private JDialog createDialog(Component frame) {
    Object[] buttons = new Object[] {getOkButton(), getCancelButton()};
    // input panel with text area and choice box
    JPanel input = new JPanel();
    input.setLayout(new BorderLayout());
    input.setPreferredSize(new Dimension(300, 150));
    input.add(new JLabel("<html><b>Enter value:"), BorderLayout.NORTH);
    input.add(new JScrollPane(getTextArea()), BorderLayout.CENTER);
    input.add(getChoiceBox(), BorderLayout.SOUTH);
    JPanel main = new JPanel();
    main.setLayout(new BorderLayout());
    main.add(input, BorderLayout.CENTER);
    if (this.parsed) {
        JPanel errorPanel = new JPanel(new BorderLayout());
        errorPanel.add(getErrorLabel());
        main.add(errorPanel, BorderLayout.SOUTH);
        main.add(createSyntaxPanel(), BorderLayout.EAST);
    }
    JOptionPane panel = new JOptionPane(main, JOptionPane.PLAIN_MESSAGE,
        JOptionPane.OK_CANCEL_OPTION, null, buttons);
    JDialog result = panel.createDialog(frame, this.title);
    result.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    result.addWindowListener(this.closeListener);
    return result;
}
 
開發者ID:meteoorkip,項目名稱:JavaGraph,代碼行數:28,代碼來源:StringDialog.java

示例5: show

public int show()
{
    int optionType = JOptionPane.OK_CANCEL_OPTION;
    Object optionSelection = null;

    if(options.length != 0)
    {
        optionSelection = options[optionIndex];
    }

    int selection = JOptionPane.showOptionDialog(rootPane,
            components.toArray(), title, optionType, messageType, null,
            options, optionSelection);

    return selection;
}
 
開發者ID:Joshuagollaher,項目名稱:HawkEngine,代碼行數:16,代碼來源:CustomDialog.java

示例6: inputPassword

@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("Auhtentication 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;
	}
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:28,代碼來源:GUIInputHandler.java

示例7: getOptionPane

private JOptionPane getOptionPane() {
    if (this.optionPane == null) {
        this.optionPane =
            new JOptionPane(getMessagePanel(), JOptionPane.QUESTION_MESSAGE,
                JOptionPane.OK_CANCEL_OPTION);
        this.optionPane.addPropertyChangeListener(this.listener);
    }
    return this.optionPane;
}
 
開發者ID:meteoorkip,項目名稱:JavaGraph,代碼行數:9,代碼來源:ExploreWarningDialog.java

示例8: getOptionPane

/**
 * Lazily creates and returns the option pane that is to form the content of
 * the dialog.
 */
private JOptionPane getOptionPane() {
    if (this.optionPane == null) {
        JTextField nameField = getNameField();
        this.optionPane = new JOptionPane(new Object[] {nameField, getErrorLabel()},
            JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null,
            new Object[] {getOkButton(), getCancelButton()});
    }
    return this.optionPane;
}
 
開發者ID:meteoorkip,項目名稱:JavaGraph,代碼行數:13,代碼來源:FreshNameDialog.java

示例9: getContentPane

JOptionPane getContentPane() {
    if (this.pane == null) {
        int mode;
        Object[] buttons;
        mode = JOptionPane.OK_CANCEL_OPTION;
        buttons = new Object[] {getOkButton(), createCancelButton()};
        this.pane =
            new JOptionPane(createTablePane(), JOptionPane.PLAIN_MESSAGE, mode, null, buttons);
    }
    return this.pane;
}
 
開發者ID:meteoorkip,項目名稱:JavaGraph,代碼行數:11,代碼來源:PropertiesDialog.java

示例10: getOptionPane

/**
 * Lazily creates and returns the option pane that is to form the content of
 * the dialog.
 */
private JOptionPane getOptionPane() {
    if (this.optionPane == null) {
        this.optionPane =
            new JOptionPane(getNumberPanel(), JOptionPane.PLAIN_MESSAGE,
                JOptionPane.OK_CANCEL_OPTION, null, new Object[] {getOkButton(),
                    getCancelButton()});
    }
    return this.optionPane;
}
 
開發者ID:meteoorkip,項目名稱:JavaGraph,代碼行數:13,代碼來源:NumberDialog.java

示例11: getContentPane

/**
 * @return the contentpane
 */
JOptionPane getContentPane() {
    Object[] buttons = new Object[] {getOkButton(), getCancelButton()};
    if (this.pane == null) {
        this.pane =
            new JOptionPane(createPanel(), JOptionPane.PLAIN_MESSAGE,
                JOptionPane.OK_CANCEL_OPTION, null, buttons);
        ToolTipManager.sharedInstance().registerComponent(this.pane);
        // new JOptionPane(createPanel(), JOptionPane.PLAIN_MESSAGE,
        // JOptionPane.OK_CANCEL_OPTION, null, buttons);
    }
    return this.pane;
}
 
開發者ID:meteoorkip,項目名稱:JavaGraph,代碼行數:15,代碼來源:SaveLTSAsDialog.java

示例12: createDialog

public void createDialog() {
    if(running) {
        return;
    }
    pane = new JOptionPane(message, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, iconplus.getImageIcon(), options, null);
}
 
開發者ID:Panzer1119,項目名稱:JAddOn,代碼行數:6,代碼來源:JWaitingDialog.java

示例13: readFromGUI

/**
 * 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);
   }
}
 
開發者ID:OpenDA-Association,項目名稱:OpenDA,代碼行數:59,代碼來源:UsernamePassword.java

示例14: createContentPane

JOptionPane createContentPane() {
    Object[] buttons = new Object[] {getOkButton(), getCancelButton()};
    this.pane = new JOptionPane(createPanel(), JOptionPane.PLAIN_MESSAGE,
        JOptionPane.OK_CANCEL_OPTION, null, buttons);
    return this.pane;
}
 
開發者ID:meteoorkip,項目名稱:JavaGraph,代碼行數:6,代碼來源:BoundedModelCheckingDialog.java

示例15: setCallback

void setCallback(ConfirmationCallback callback)
    throws UnsupportedCallbackException
{
    this.callback = callback;

    int confirmationOptionType = callback.getOptionType();
    switch (confirmationOptionType) {
    case ConfirmationCallback.YES_NO_OPTION:
        optionType = JOptionPane.YES_NO_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.NO
        };
        break;
    case ConfirmationCallback.YES_NO_CANCEL_OPTION:
        optionType = JOptionPane.YES_NO_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.OK_CANCEL_OPTION:
        optionType = JOptionPane.OK_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.OK_OPTION, ConfirmationCallback.OK,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.UNSPECIFIED_OPTION:
        options = callback.getOptions();
        /*
         * There's no way to know if the default option means
         * to cancel the login, but there isn't a better way
         * to guess this.
         */
        translations = new int[] {
            JOptionPane.CLOSED_OPTION, callback.getDefaultOption()
        };
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized option type: " + confirmationOptionType);
    }

    int confirmationMessageType = callback.getMessageType();
    switch (confirmationMessageType) {
    case ConfirmationCallback.WARNING:
        messageType = JOptionPane.WARNING_MESSAGE;
        break;
    case ConfirmationCallback.ERROR:
        messageType = JOptionPane.ERROR_MESSAGE;
        break;
    case ConfirmationCallback.INFORMATION:
        messageType = JOptionPane.INFORMATION_MESSAGE;
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized message type: " + confirmationMessageType);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:66,代碼來源:DialogCallbackHandler.java


注:本文中的javax.swing.JOptionPane.OK_CANCEL_OPTION屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。