本文整理汇总了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;
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例12: createDialog
public void createDialog() {
if(running) {
return;
}
pane = new JOptionPane(message, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, iconplus.getImageIcon(), options, null);
}
示例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);
}
}
示例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;
}
示例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);
}
}