DisplayService does not close window

scijava
imagej
imagej2

#1

Maybe I am doing something wrong here, but I would expect that this should close the image Window.
Bellow is the code to reproduce he issue:

@Plugin(type = Command.class, menuPath = "Plugins > Display Service Test")
public class DisplayPlugin implements Command {

    @Parameter
    ImgPlus imgp;

    @Parameter
    DisplayService display;

    @Override
    public void run() {
        Display disp = display.getDisplay(imgp.getName());
        disp.close();
    }


    public static void main(String[] args) throws IOException {
        ImageJ ij = new ImageJ();
        ij.ui().showUI();

        ImagePlus imp = new ImagePlus("http://imagej.nih.gov/ij/images/blobs.gif");
        Img img = ImageJFunctions.wrap(imp);
        ImgPlus imgp = new ImgPlus(img, "blobs");
        ij.ui().show(imgp);
        
        ij.command().run(DisplayPlugin.class, true);
    }
}

I also tried creating the image display with ij.display().createDisplay(imgp); but the result stays the same: The window remains open, calling close() does not seem to have any effect.

Edit: My current workaround is to grab the frame with JFrame.getFrames() and comparing titles.


#2

Does your project contain the imagej-legacy dependency?


#3

yes, the imagej-legacy dependency is there.


#4

I can confirm that the issue is within imagej-legacy. Displays are properly closed when it’s not on the classpath. I’ll investigate!


#5