Login  Register

Re: Urgent: Unable to terminate plug-in

Posted by Michael Schmid on Jul 12, 2015; 8:23am
URL: http://imagej.273.s1.nabble.com/Urgent-Unable-to-terminate-plug-in-tp5013523p5013526.html

On Sun, July 12, 2015 04:58, hlee19 wrote:

> Hello,
> This is very urgent, so any help would be greatly appreciated!
>
> I am coding an ImageJ plug-in and when I open a dialog box to ask the user
> to select something, I can't seem to terminate it when the user clicks the
> red x in the upper right hand corner, nor when the user selects the Cancel
> button.
>
> 1) IJ.showMessageWithCancel does return false when Cancel is selected, but
> I
> think the plugin is called again and again and so the program doesn't
> actually end. Is there a solution for this?
> 2) Is there a way for the code to return when the user selects the red x?

Hi anonymous,

The IJ.showMessageWithCancel method is a GenericDialog, like most ImageJ
dialogs. For sure, it does not reappear. If it reappears, this must be
your code that calls it again.

Quickly looking at the code, it seems to me that closing the dialog box of
IJ.showMessageWithCancel makes it return true. This makes sense if the
user should 'cancel' only in special cases.

If you want it to return false when closed without pressing a button,
simply copy the code from IJ.showMessageWithCancel and return
gd.wasOKed(), e.g.:

  /** Displays a message in a dialog box with the specified title.
      Returns true only if the user pressed "OK". */
  static boolean showMessageReturnOKed(String title, String msg) {
    GenericDialog gd = new GenericDialog(title);
    gd.addMessage(msg);
    gd.showDialog();
    return gd.wasOKed();
  }


Michael

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html