Login  Register

Re: subtle interaction request

Posted by Wayne Rasband-2 on Feb 05, 2019; 3:45pm
URL: http://imagej.273.s1.nabble.com/subtle-interaction-request-tp5021743p5021747.html

> On Feb 4, 2019, at 5:07 PM, Kenneth Sloan <[hidden email]> wrote:
>
> In a Java plugin:
>
> I have an image open...
>
> I want to display a NonBlockingGenericDialog (or, something else that will have the same effect)
>
> BUT...I want the image window to be selected - without user interaction.
>
> The problem is that I want to use the SPACE bar to toggle an overlay on/off - but if the user gets sloppy and
> hits the SPACE bar while the dialog window is still on top...it is CANCELed.  Once I display the dialog box,
> my program can't do anything.  Catch-22.

This is a “feature” of the Dialog class, which GenericDialog and NonBlockingGenericDialog extend. Pressing the space bar cancels the dialog if there are no focusable components other than the buttons on the bottom. You can work around this problem by adding at least one focusable component to the dialog.

The following JavaScript code reproduces the problem. Uncomment the second line to work around it.

   gd = new NonBlockingGenericDialog("Dialog");
   //gd.addStringField("","",0);
   gd.addMessage("SPACE = Cancel");
   gd.addMessage("ENTER = OK");
   gd.showDialog();
   if (gd.wasCanceled())
      IJ.log("Cancel");
   if (gd.wasOKed())
      IJ.log("OK”);

-wayne

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