Java Code Examples for javax.swing.JOptionPane.QUESTION_MESSAGE

The following are Jave code examples for showing how to use QUESTION_MESSAGE of the javax.swing.JOptionPane class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: AutoUpgrade.java   View Source Code Vote up 6 votes
private static boolean showUpgradeDialog (final File source, String note) {
       Util.setDefaultLookAndFeel();

JPanel panel = new JPanel(new BorderLayout());
panel.add(new AutoUpgradePanel (source.getAbsolutePath (), note), BorderLayout.CENTER);
JProgressBar progressBar = new JProgressBar(0, 100);
progressBar.setValue(0);
progressBar.setStringPainted(true);
progressBar.setIndeterminate(true);
panel.add(progressBar, BorderLayout.SOUTH);
progressBar.setVisible(false);

JButton bYES = new JButton("Yes");
bYES.setMnemonic(KeyEvent.VK_Y);
JButton bNO = new JButton("No");
bNO.setMnemonic(KeyEvent.VK_N);
JButton[] options = new JButton[] {bYES, bNO};
       JOptionPane p = new JOptionPane (panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null, options, bYES);
       JDialog d = Util.createJOptionProgressDialog(p, NbBundle.getMessage (AutoUpgrade.class, "MSG_Confirmation_Title"), source, progressBar);
       d.setVisible (true);

       return new Integer (JOptionPane.YES_OPTION).equals (p.getValue ());
   }
 
Example 2
Project: JavaGraph   File: BehaviourOption.java   View Source Code Vote up 6 votes
/**
 * Indicates if this option is confirmed. This can be either because its
 * value is {@link #ALWAYS}, or because the user has confirmed an
 * appropriate dialog.
 * @param owner the component on which the dialog is to be shown
 * @param question if not <code>null</code>, replaces the name of the
 *        option in the dialog
 * @return <code>true</code> if the option is confirmed.
 */
public boolean confirm(Component owner, String question) {
    if (this.value == ASK) {
        if (question == null) {
            question = getText();
        }
        List<String> options = getDialogOptions();
        JOptionPane pane =
            new JOptionPane(question, JOptionPane.QUESTION_MESSAGE,
                JOptionPane.YES_NO_CANCEL_OPTION, null, options.toArray());
        pane.createDialog(owner, DIALOG_TITLE).setVisible(true);
        int dialogValue = options.indexOf(pane.getValue());
        if (dialogValue > NO) {
            setValue(dialogValue - 1);
        }
        return dialogValue == YES || dialogValue - 1 == ALWAYS;
    } else {
        return this.value == ALWAYS;
    }
}
 
Example 3
Project: rapidminer   File: GUIInputHandler.java   View Source Code Vote up 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("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;
	}
}
 
Example 4
Project: JavaGraph   File: ExploreWarningDialog.java   View Source Code Vote up 5 votes
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;
}
 
Example 5
Project: marathonv5   File: CustomDialog.java   View Source Code Vote up 4 votes
/** Creates the reusable dialog. */
public CustomDialog(Frame aFrame, String aWord, DialogDemo parent) {
    super(aFrame, true);
    dd = parent;

    magicWord = aWord.toUpperCase();
    setTitle("Quiz");

    textField = new JTextField(10);

    // Create an array of the text and components to be displayed.
    String msgString1 = "What was Dr. SEUSS's real last name?";
    String msgString2 = "(The answer is \"" + magicWord + "\".)";
    Object[] array = { msgString1, msgString2, textField };

    // Create an array specifying the number of dialog buttons
    // and their text.
    Object[] options = { btnString1, btnString2 };

    // Create the JOptionPane.
    optionPane = new JOptionPane(array, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null, options, options[0]);

    // Make this dialog display it.
    setContentPane(optionPane);

    // Handle window closing correctly.
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent we) {
            /*
             * Instead of directly closing the window, we're going to change
             * the JOptionPane's value property.
             */
            optionPane.setValue(new Integer(JOptionPane.CLOSED_OPTION));
        }
    });

    // Ensure the text field always gets the first focus.
    addComponentListener(new ComponentAdapter() {
        public void componentShown(ComponentEvent ce) {
            textField.requestFocusInWindow();
        }
    });

    // Register an event handler that puts the text into the option pane.
    textField.addActionListener(this);

    // Register an event handler that reacts to option pane state changes.
    optionPane.addPropertyChangeListener(this);
}
 
Example 6
Project: OpenDA   File: UsernamePassword.java   View Source Code Vote up 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 7
Project: SE2017-Team2   File: CustomOptionPane.java   View Source Code Vote up 4 votes
public CustomOptionPane(String head, String inputRequest, String opt1, String opt2, String graph) {
	super(new JFrame(), true);
	this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
	this.graph = graph;
	// setLocationRelativeTo(null);
	this.setTitle(head);
	this.setLayout(new FlowLayout());
	this.newGraph = new JRadioButton(opt1);
	this.newGraph.setActionCommand("new_graph");
	this.newGraph.addActionListener(this);
	this.newGraph.setSelected(true);

	this.exsitingGraph = new JRadioButton(opt2);
	this.exsitingGraph.setActionCommand("exsisting_graph");
	this.exsitingGraph.addActionListener(this);

	this.eventIDField = new HintTextField(inputRequest);

	this.graphIDField = new HintTextField("Please enter ID of the existing " + graph);
	this.graphIDField.setForeground(Color.gray);
	this.graphIDField.setEnabled(false);

	this.okButton = new JButton("Enter");
	this.okButton.addActionListener(this);

	this.cancelButton = new JButton("Cancel");
	this.cancelButton.addActionListener(this);

	Object[] array = { inputRequest, eventIDField, newGraph, exsitingGraph, graphIDField };
	Object[] options = { this.okButton, this.cancelButton };

	optionPane = new JOptionPane(array, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null, options,
			null);
	setContentPane(optionPane);

	label = new JLabel("Please select one of the options");
	this.label.setForeground(Color.red);
	this.label.setAlignmentX(RIGHT_ALIGNMENT);
	Border border = this.label.getBorder();
	Border margin = new EmptyBorder(10, 0, 0, 10);
	this.label.setBorder(new CompoundBorder(border, margin));
	this.label.setVisible(false);
	this.add(label);

	addWindowListener(new WindowAdapter() {
		public void windowClosing(WindowEvent we) {
			/*
			 * Instead of directly closing the window, we're going to change
			 * the JOptionPane's value property.
			 */
			optionPane.setValue(new Integer(JOptionPane.CLOSED_OPTION));
		}
	});

	this.pack();
	this.setVisible(true);

}
 
Example 8
Project: SE2017-Team2   File: DeleteSubGraphOptionPane.java   View Source Code Vote up 4 votes
public DeleteSubGraphOptionPane(String head, String opt1, String opt2) {
	super(new JFrame(), true);
	// setLocationRelativeTo(null);

	this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
	this.newGraph = new JRadioButton(opt1);
	this.newGraph.setActionCommand("new_graph");
	this.newGraph.addActionListener(this);
	// this.newGraph.setSelected(true);

	this.exsitingGraph = new JRadioButton(opt2);
	this.exsitingGraph.setActionCommand("exsisting_graph");
	this.exsitingGraph.addActionListener(this);

	this.graphIDField = new HintTextField("Please enter ID of the existing graph   ");
	this.graphIDField.setForeground(Color.gray);
	// this.graphIDField.setEnabled(false);

	this.okButton = new JButton("Enter");
	this.okButton.addActionListener(this);

	this.cancelButton = new JButton("Cancel");
	this.cancelButton.addActionListener(this);

	Object[] array = { head, graphIDField, newGraph, exsitingGraph };
	Object[] options = { this.okButton, this.cancelButton };

	optionPane = new JOptionPane(array, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null, options,
			options[0]);
	setContentPane(optionPane);

	addWindowListener(new WindowAdapter() {
		public void windowClosing(WindowEvent we) {
			/*
			 * Instead of directly closing the window, we're going to change
			 * the JOptionPane's value property.
			 */
			optionPane.setValue(new Integer(JOptionPane.CLOSED_OPTION));
		}
	});

	label = new JLabel("Please select one of the options");
	this.label.setForeground(Color.red);
	this.label.setAlignmentX(RIGHT_ALIGNMENT);
	Border border = this.label.getBorder();
	Border margin = new EmptyBorder(10, 0, 0, 10);
	this.label.setBorder(new CompoundBorder(border, margin));
	this.label.setVisible(false);
	this.add(label);

	this.pack();
	this.setVisible(true);

}