p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_java thread: Re: Bouncing showConfirmDialog


Message #1 by "Robert Mrozek" <robmrozek@y...> on Tue, 16 Apr 2002 11:38:01
Hmmmm.  This problem has been bugging me for days, and within minutes of 
posting the message I try my application and it works fine!  I'm not sure 
I understand why, exactly, but my application was busy doing something 
else at the same time (not quite deadlock - but tied up!) - which sorted 
out last night - and this seems to have solved the problem.

Rob
Message #2 by "Robert Mrozek" <robmrozek@y...> on Tue, 16 Apr 2002 11:30:27
> Can anyone see anything wrong with the following code?  I just have a 
C> lose button for which this application is a registered listener, so I 
d> on't have to try to identify it.

> It works perfectly when the YES or NO options are chosen.  But when 
CANCEL 
i> s chosen, the dialog disappears for a moment and then reappears.  When 
I 
c> hoose CANCEL again, it disappears as it should.

> I'd be grateful for any help/advice!  Thanks, Rob

>   public void actionPerformed(ActionEvent e)  {

>     int response = JOptionPane.showConfirmDialog(
	> 			this,
	> 			"Do you want to save the log?",
	> 			"Application shutting down ...",
	> 			JOptionPane.YES_NO_CANCEL_OPTION,
	> 			JOptionPane.QUESTION_MESSAGE);
 >    switch(response)  {

> 	case JOptionPane.YES_OPTION:
	>   saveLog();
	>   theApp.close();
	>   dispose();
	>   break;
	> case JOptionPane.NO_OPTION:
	>   theApp.close();
	>   dispose();
	>   break;
	> default:
	>   return;
 >    }
 >  }
Message #3 by "Robert Mrozek" <robmrozek@y...> on Tue, 16 Apr 2002 11:13:49
Can anyone see anything wrong with the following code?  I just have a 
Close button for which this application is a registered listener, so I 
don't have to try to identify it.

It works perfectly when the YES or NO options are chosen.  But when CANCEL 
is chosen, the dialog disappears for a moment and then reappears.  When I 
choose CANCEL again, it disappears as it should.

I'd be grateful for any help/advice!  Thanks, Rob

  public void actionPerformed(ActionEvent e)  {

    int response = JOptionPane.showConfirmDialog(
				this,
				"Do you want to save the log?",
				"Application shutting down ...",
				JOptionPane.YES_NO_CANCEL_OPTION,
				JOptionPane.QUESTION_MESSAGE);
    switch(response)  {

	case JOptionPane.YES_OPTION:
	  saveLog();
	  theApp.close();
	  dispose();
	  break;
	case JOptionPane.NO_OPTION:
	  theApp.close();
	  dispose();
	  break;
	default:
	  return;
    }
  }

  Return to Index