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