Java Confirmation box pop-up

Source: Internet
Author: User

Recently at work, there is a small need to upload files into the TC, if the file exists in the TC, you need to pop up a selection box to allow customers to choose. such as:

In order to achieve the above results, there are several workarounds.

1) Method 1: not associated with thread

1 int showconfirmdialog = Joptionpane.showconfirmdialog (null, "already exists, overwrite?", "Select", Joptionpane.yes_no _option);

Depending on the choice, there are four different types, namely Joptionpane.yes_option, Joptionpane.no_option, Joptionpane.cancel_option, Joptionpane.closed_ OPTION

When we click "Yes", the return value is 0;

When we click "No", the return value is 1;

When we click "X", the selection box is closed and the return value is-1.

Cancel the situation, I do not know the click on which, welcome to know the small partners tell me.

2) Method 2: associated with thread

Shell shell = display.getcurrent (). Getactiveshell (); int option = confirmdialog.prompt (Shell, "Please select", "already exists \ n overwrite?") (select No new Table) ");

It is said that when you click "Yes", the return value is 2;

When you click "No", the return value is 3.

As to whether it is true, please test them yourself.

3) Method 3: Associated with the thread:

boolean confirm = Messagedialog.openquestion (null, "ACK", "already exists, is it overwritten?") ");

When you click "Yes", the return is true;

When you click "No", the return is false.

Java Confirmation box pop-up

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.