How do I close this JOptionPane upon clicking?

Lancer521

My JOptionPane shows up just fine, but when I click the button, nothing happens. Once I click the 'X', the console will print which of the buttons was clicked. It just won't close when the button is clicked:

final JOptionPane newDocWarning = new JOptionPane("Would you like to save before opening a new file?", JOptionPane.WARNING_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION);
final JDialog newDocDialog = new JDialog(this, "New Document", true);                

newDocDialog.setContentPane(newDocWarning);
newDocDialog.setSize(420, 150);
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); 
newDocDialog.setLocation(dim.width/2-newDocDialog.getSize().width/2, dim.height/2- newDocDialog.getSize().height/2);
newDocDialog.setVisible(true);

int value = ((Integer)newDocWarning.getValue()).intValue();

if(value == JOptionPane.YES_OPTION){
    System.out.println("YES OPTION WAS CLICKED");
    newDocDialog.dispose();
}else if(value == JOptionPane.NO_OPTION){
    System.out.println("NO OPTION WAS CLICKED");
    newDocDialog.setVisible(false);
}else if(value == JOptionPane.CANCEL_OPTION){
    System.out.println("CANCEL OPTION WAS CLICKED");
    newDocWarning.setVisible(false);
}
Braj

Can you try this one using JOptionPane.showConfirmDialog()

int value = JOptionPane.showConfirmDialog(frame,
        "Would you like to save before opening a new file?", "New Document",
        JOptionPane.INFORMATION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION);

In this case you don't need to close it. It will be automatically closed once any button is clicked.

For more info have a look at How to Make Dialogs.

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I close a window by clicking on it?

From Dev

How do I change a glyphicon upon clicking it in Bootstrap 3.2?

From Dev

How do I change one image to another upon clicking on a button

From Dev

How Do I Set My Fedora KDE 33 Workstation To NOT Suspend Upon Lid Close?

From Dev

How do I shift the page-scroll for each html section to jump to the top of each section upon clicking its corresponding link in the navbar?

From Dev

How do I "close" this responsive dropdown menu after clicking a menu item?

From Dev

How to close a menu by clicking on it

From Dev

How do I use JOptionPane.showInputDialog with a class I created?

From Dev

How to pass and use URL in jQuery function and how to resolve the issue in closing the Bootstrap modal upon clicking close icon on modal?

From Dev

How can I close the suggestion box when clicking outside

From Dev

Do not close ToolStripMenu on clicking in winforms

From Dev

Do not close ToolStripMenu on clicking in winforms

From Dev

How do I change the size and location of JOptionPane.showOptionDialog()

From Dev

How to toggle an animation upon clicking a button

From Dev

How to add a border to a cell upon clicking

From Dev

How to uncheck radio button upon double clicking?

From Dev

How to toggle an animation upon clicking a button

From Dev

How to uncheck radio button upon double clicking?

From Dev

how to make a form disappear upon clicking submit?

From Dev

How to get button's id upon clicking it?

From Dev

How can i get the uilabel text changed upon clicking a UIbuttion in the UITableViewCell

From Dev

How do I execute jQuery by clicking a link?

From Dev

How Do I Open Text by Clicking on An Image?

From Dev

How to close this menu clicking outside?

From Dev

how to close an overlay by clicking the page

From Dev

In Jasmine, how do I stub out a spied upon method?

From Dev

How do I make text slide to the right upon page load?

From Dev

How do I create a java library that is dependent upon another library?

From Dev

How do I readjust rows in bootstrap upon window resize?

Related Related

  1. 1

    How do I close a window by clicking on it?

  2. 2

    How do I change a glyphicon upon clicking it in Bootstrap 3.2?

  3. 3

    How do I change one image to another upon clicking on a button

  4. 4

    How Do I Set My Fedora KDE 33 Workstation To NOT Suspend Upon Lid Close?

  5. 5

    How do I shift the page-scroll for each html section to jump to the top of each section upon clicking its corresponding link in the navbar?

  6. 6

    How do I "close" this responsive dropdown menu after clicking a menu item?

  7. 7

    How to close a menu by clicking on it

  8. 8

    How do I use JOptionPane.showInputDialog with a class I created?

  9. 9

    How to pass and use URL in jQuery function and how to resolve the issue in closing the Bootstrap modal upon clicking close icon on modal?

  10. 10

    How can I close the suggestion box when clicking outside

  11. 11

    Do not close ToolStripMenu on clicking in winforms

  12. 12

    Do not close ToolStripMenu on clicking in winforms

  13. 13

    How do I change the size and location of JOptionPane.showOptionDialog()

  14. 14

    How to toggle an animation upon clicking a button

  15. 15

    How to add a border to a cell upon clicking

  16. 16

    How to uncheck radio button upon double clicking?

  17. 17

    How to toggle an animation upon clicking a button

  18. 18

    How to uncheck radio button upon double clicking?

  19. 19

    how to make a form disappear upon clicking submit?

  20. 20

    How to get button's id upon clicking it?

  21. 21

    How can i get the uilabel text changed upon clicking a UIbuttion in the UITableViewCell

  22. 22

    How do I execute jQuery by clicking a link?

  23. 23

    How Do I Open Text by Clicking on An Image?

  24. 24

    How to close this menu clicking outside?

  25. 25

    how to close an overlay by clicking the page

  26. 26

    In Jasmine, how do I stub out a spied upon method?

  27. 27

    How do I make text slide to the right upon page load?

  28. 28

    How do I create a java library that is dependent upon another library?

  29. 29

    How do I readjust rows in bootstrap upon window resize?

HotTag

Archive