Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

multiple clicks required to close JOptionPane  RSS feed

 
John Kilbourne
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Has anyone had trouble with a JOptionPane that only closes after two clicks on the OK button? I thought the problem was using "null" as the parent, but that doesn't matter. This should be simple.
 
anandh
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It indeed is simple. It does not need multiple clicks to close it. Check the showMessageDialog() call again.
 
John Kilbourne
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't quite follow your reply.
I have noticed that this only occurs in the FocusAdapter methods, but not in ActionPerformed methods. As far as I can tell, I'm only calling the JOptionPane() static method once; the code is simple. I'm thinking of just making a couple of textfields and a button, and two FocusListeners and an ActionListener in a JFrame to simplify the problem to its basics, but I have a deadline looming that thwarts my exploration.
if nobody else has seen this, then that helps too. There are about 3 or 4 un-responded to threads on the Java Sun Forums site about this, so I know I'm not the only one who has seen it. Outside of the Focus listener, the problem does not show up for me.
 
Renee Zhang
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anandh is so smart!
you can change nothing but the button name in the JOptionPane. (You can't addActionListener to the button) So declare an integer at first.
private int clickTimes = 1;
while (clickTimes %2 ==1) {
JOptionPane.show...Message(null, "The String you want to display");
clickTimes ++;
//If you want to repeatly show JOptionPane, put your other code here
......
}

you won't nitice that is a new JOptionPane because they are the same!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!