You should actually take the result from the option pane:
dialogButton = JOptionPane.showConfirmDialog (null, "Are you sure?","WARNING", dialogButton);
Otherwise, it remains set to JOptionPane.YES_NO_OPTION
.
Cleaner would be:
if (JOptionPane.showConfirmDialog(null, "Are you sure?", "WARNING", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { // yes option } else { // no option }
Although, I’m not sure what this line is expected to do in the posted code: remove(dialogButton);
.
For more details and examples check out How to Make Dialogs tutorial.
Related Posts:
- Getting a HeadlessException: No X11 DISPLAY variable was set
- addMouseListener for a JPanel
- Setting background color for a JFrame
- JOptionPane Yes or No window
- Problem with gif with transparent background
- How change the color arrowIcon to JMenu when it is selected
- Unsupported major.minor version 52.0 [duplicate]
- Unsupported major.minor version 52.0 [duplicate]
- error upon assigning Layout: BoxLayout can’t be shared
- Return string Input with parse.string
- How do I draw a triangle?
- Java: Rotating Images
- How do I draw a triangle?
- What does “AL lib: alc_cleanup: 1 device not closed” mean?
- Java GUI: about getContentPane( ) method and content
- Java Embedding Into HTML
- How to center the text in a JLabel?
- How to add an image to a JPanel?
- How to repaint a JPanel after have drawn on it?
- Implementing an actionlistener to a JTextField
- How to Set JPanel’s Width and Height?
- .class vs .java
- How to use Java AWT setBackground
- Swing/Java: How to use the getText and setText string properly
- What does super.paintComponent(g) do?
- Java: Custom Buttons in showInputDialog
- How to Set the Background Color of a JButton on the Mac OS
- Java Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException
- Popup Message boxes
- Exception in thread “AWT-EventQueue-0”?
- make a JLabel wrap it’s text by setting a max width
- Keylistener not working for JPanel
- setMnemonic() and call a method by pressing the key
- the getSource() and getActionCommand()
- How to programmatically close a JFrame
- How does addNotify() and requestFocus() work in Java with JPanel?
- DTO and DAO concepts and MVC
- Adding JPanel to JFrame
- Adding image to JFrame
- How to Retrieve value from JTextField in Java Swing?
- What does .pack() do?
- Setting background images in JFrame
- Java Swing revalidate() vs repaint()
- KeyPressed event in java
- How does paintComponent work?
- How can I set size of a button?
- Java Swing setting JPanel Size
- How to draw a circle with given X and Y coordinates as the middle spot of the circle?
- What exactly is Apache Camel?
- What is an instance variable in Java?
- How does the Java ‘for each’ loop work?
- How does the Java ‘for each’ loop work?
- What does “Could not find or load main class” mean?
- How do I create a file and write to it?
- When to use LinkedList over ArrayList in Java?
- How do I generate random integers within a specific range in Java?
- “Exception in thread “main” java.lang.IndexOutOfBoundsException: Index: 0, Size: 0″ with ArrayList?
- Raising a number to a power in Java
- java.io.FileNotFoundException: the system cannot find the file specified
- How to parse this string in Java?
- How to match “any character” in regular expression?
- Double array initialization in Java
- Convert java.util.Date to String
- How do I do a deep copy of a 2d array in Java?
- Returning an empty array
- Java Security: Illegal key size or default parameters?
- Could not reserve enough space for object heap
- Eclipse: Java was started but returned error code=13
- Why java unknown: import org.apache.commons.codec.binary.Base64;?
- Extracting .jar file with command line
- Unable to create requested service [org.hibernate .engine.jdbc.env.spi.JdbcEnvironment]-MySQL
- Good Java graph algorithm library?
- Integrate Ant builder into Eclipse: Error “Variable references empty selection”
- Spring Maven clean error – The requested profile “pom.xml” could not be activated because it does not exist
- Java Class File Editor
- Error Importing SSL certificate : Not an X.509 Certificate
- RecyclerView onClick
- Java, Shifting Elements in an Array
- error: bad operand types for binary operator ‘&&’
- Exception in thread “main” java.lang.ArithmeticException: / by zero
- Failed to load the JNI shared Library (JDK)
- “com.jcraft.jsch.JSchException: Auth fail” with working passwords
- java.util.NoSuchElementException – Scanner reading user input
- How would I use a while loop to keep requesting user input
- Array Required, but java.lang.String found
- Eclipse java debugging: source not found
- Android For loop
- Java project in Eclipse: The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
- How to easily convert a BufferedReader to a String?
- How can I calculate a time difference in Java?
- Detecting a long press with Android
- How to increase the size of an array in Java?
- Cannot invoke toString() on the primitive type int
- Android: how to create Switch case from this?
- Read next word in java
- Convert float to double without losing precision
- Exception in thread “AWT-EventQueue-0” java.lang.OutOfMemoryError: Java heap space
- How do the post increment (i++) and pre increment (++i) operators work in Java?
- Manually throw an exception
- Spring boot: Unable to start embedded Tomcat servlet container