Hi Fred,

the keyTyped callback runs in the EventQueue thread.
Showing an image also needs the EventQueue, so it cannot happen until the keyTyped function has finished. You need to start a new thread in keyTyped. In that thread you can call ImagePlus.waitTillActivated.

All the best for 2026 to everyone in the ImageJ community!

Michael
________________________________________________________________
On 03.01.26 01:31, Fred Damen wrote:
Greetings,

How should the (keyboard) focus be maintained by an ImageWindow
(cimp.getWindow) through (after) a KeyListener/KeyTyped method on an
ImageCanvas (cimp.getCanvas) whilst a tmpNextImp.show is performed (see
code below)? I assume that the actual show(ing) of tmpNextImp happens
asynchronously after keyTyped has returned. I assume that either I will
need to 'show' tmpNextImp without letting it get the focus, OR, somehow
get use a callback after it has been show(en); Any guidance would be
appreciated.

If the 'if (true) return' if placed before the tmpNextImp.show the
keyboard focus is maintained; anywhere after it is not. All of the
following code gives the impression that focus is maintained, although
tmpNextImp becomes the focused (active) window. tmpNextImp is not shown
until after the IJ.wait has expired.

Thanks in advance,

Fred




    public void keyTyped(KeyEvent e) {
IJ.log("Start");
       ImageCanvas cimp = ((ImageCanvas)e.getSource()).getImage();
       ImagePlus tmpNextImp = cimp.duplicate();
//if (true) return;
       tmpNextImp.show();
       tmpNextImp.waitTillActivated();
if (true) return;
       IJ.log("isFocused="+cimp.getWindow().isFocused());
       IJ.log("isFocusableWindow()="+cimp.getWindow().isFocusableWindow());
       WindowManager.setCurrentWindow​(cimp.getWindow());
       WindowManager.toFront(cimp.getWindow());
       cimp.getWindow().setAutoRequestFocus(true);
       cimp.getWindow().setVisible(true);
       cimp.getWindow().toFront();
       IJ.log("cimp.getWindow().requestFocus()");
cimp.getWindow().requestFocus();
       IJ.log("cimp.getCanvas().requestFocus()");
cimp.getCanvas().requestFocus();
       IJ.log("isFocused=>"+cimp.getWindow().isFocused());
       IJ.log("isFocusableWindow()=>"+cimp.getWindow().isFocusableWindow());
       cimp.show();
IJ.log("End");
IJ.wait(10000);
       }

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

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

Reply via email to