JOptionPane YES NO OPTION

You should actually take the result from the option pane: Otherwise, it remains set to JOptionPane.YES_NO_OPTION. Cleaner would be: 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.