aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How prevent the user closing the Joptionpane by clicking the X in the right end corner Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How prevent the user closing the Joptionpane by clicking the X in the right end corner" Watch "How prevent the user closing the Joptionpane by clicking the X in the right end corner" New topic
Author

How prevent the user closing the Joptionpane by clicking the X in the right end corner

Vinod Joseph
Greenhorn

Joined: Aug 11, 2011
Posts: 1
The requirement is if the user clicks the X in JOptionpane it should not close.

In JDialog we have setDefaultCloseOperation but i am not sure what is the functionality that we have to implement in JoptionPane similar to the setDefaultCloseOperation.

optionsConfirm[0] = new String(EJbundle.getString("YES"));
optionsConfirm[1] = new String(EJbundle.getString("NO"));
int answer = JOptionPane.showOptionDialog()

if (answer== JOptionPane.YES_OPTION) { }

if (answer == JOptionPane.CLOSED_OPTION) { If the user click the X button of the JOPTIONPANE it should not close. I know that setdefaultclose operation was in JDialog. But i am not sure how the same/alternative can be implemented in JOptionPane }

Thanks in advance.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2215
    
    7
Quit cross posting: http://www.java-forums.org/awt-swing/47524-prevent-user-close-joptionpane-using-x-button.html

Instead learn how to use one forum properly, for example, by learning how to post code properly so it is readable.

In JDialog we have setDefaultCloseOperation but i dont what can be done in JoptionPane.


Read the JOptionPane API. It shows you how to access the dialog used by the option pane.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39784
    
  28
Welcome to the Ranch

Please remember Rob Camick's advice.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How prevent the user closing the Joptionpane by clicking the X in the right end corner