• Post Reply Bookmark Topic Watch Topic
  • New Topic

JOptionPane

 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. How can I tell if a user has pressed the OK button on an error message dialog? I looked at the API, but I didn't see anything that jumped out at me.
Could someone please help?
Thanks in advance!
 
Lon Allen
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are producing the dialog with JOptionPane.showMessageDialog() you will know that the dialog was closed (either by the "OK" button being selected or the dialog closed with the "X" in the title bar) when code execution continues. This is a modal dialog so your code will halt while the JOptionPane is displayed awaiting a button selection. Once the dialog is closed your code will continue execution. This is assuming you are using JOptionPane.showMessageDialog() which doesn't return any values.
If you are needing to detect a YES or NO selection JOptionPane.showConfirmDialog() returns an int value. Just use "showConfirmDialog" in the following fashion:

Lon Allen
[ August 22, 2002: Message edited by: Lon Allen ]
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's just what I needed to know! I am using showMessageDialog(). Thanks for your help. I really appreciate it!
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I've run into another question about this same topic. I am using a showMessageDialog, with the only option being 'OK'. How can I tell if that OK button was pressed- in a seperate class?
 
Lon Allen
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why can't you set a global variable or call a static method to inform the "Other" class that the dialog has been disposed of. You can make the call to set the variable or call the static method from your code where the JOptionPane was created. Code execution continues in that class when the JOptionPane is closed so put it there. Just a suggestion...
Lon Allen
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!