Java Code Examples for javax.swing.JOptionPane.YES_NO_OPTION

The following are Jave code examples for showing how to use YES_NO_OPTION 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: Hollow-Knight-SaveManager   File: Listeners.java   View Source Code Vote up 6 votes
@Override
public void actionPerformed(ActionEvent e){
	System.out.println("Delete activated");
	if( gui.ft.lastClicked == null )
		return;
	int dialogButton = JOptionPane.YES_NO_OPTION;
	int dialogResult = JOptionPane.showConfirmDialog (null, "This will delete all folders and files under what you have selected. Continue?","Warning",dialogButton);
	if(dialogResult != JOptionPane.YES_OPTION)
		return;
	String path = gui.savePath;
	int c = gui.ft.lastClicked.getPath().length;
	for( int i = 1; i < c; i++ ){
		path += "/" + gui.ft.lastClicked.getPath()[i].toString();
	}
	System.out.println(path);
	deleteFiles(path);
	gui.ft.model.reload();
	System.out.println("Done");
}
 
Example 3
Project: AWGW   File: WorldFrame.java   View Source Code Vote up 6 votes
public void handle(Throwable e) {
    e.printStackTrace();

    JTextArea area = new JTextArea(10, 40);
    StringWriter writer = new StringWriter();
    e.printStackTrace(new PrintWriter(writer));
    area.setText(writer.toString());
    area.setCaretPosition(0);
    String copyOption = resources.getString("dialog.error.copy");
    JOptionPane pane = new JOptionPane(new JScrollPane(area), JOptionPane.ERROR_MESSAGE,
            JOptionPane.YES_NO_OPTION, null, new String[]{copyOption, resources.getString("cancel")});
    pane.createDialog(WorldFrame.this, e.toString()).setVisible(true);
    if (copyOption.equals(pane.getValue())) {
        area.setSelectionStart(0);
        area.setSelectionEnd(area.getText().length());
        area.copy(); // copy to clipboard
    }
}
 
Example 4
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 5
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 6
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);

}
 
Example 7
Project: OpenJSharp   File: DialogCallbackHandler.java   View Source Code Vote up 4 votes
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);
    }
}
 
Example 8
Project: jdk8u-jdk   File: DialogCallbackHandler.java   View Source Code Vote up 4 votes
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);
    }
}