DisplayService does not close window



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 {

    ImgPlus imgp;

    DisplayService display;

    public void run() {
        Display disp = display.getDisplay(imgp.getName());

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

        ImagePlus imp = new ImagePlus("http://imagej.nih.gov/ij/images/blobs.gif");
        Img img = ImageJFunctions.wrap(imp);
        ImgPlus imgp = new ImgPlus(img, "blobs");
        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.


Does your project contain the imagej-legacy dependency?


yes, the imagej-legacy dependency is there.


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