WaitForUser() not working

Posted by guillaumelobet on
URL: http://imagej.273.s1.nabble.com/WaitForUser-not-working-tp5009331.html

I am trying to use the WaitForUserDialog inside a plugin, but it freeze when used. The plugin does the following:

- display a GUI with the options for the analysis (path for the images, ...). The analysis is triggered by a actionPerformed even in the GUI.
- get a list of images and loop over them for the analysis
- if required by the user, the analysis (ROI selection) could be corrected for every image:
    - open the image
    - display the ROI
    - correct the ROI
   - close the image

So, what I need is, inside the analysis loop, to open the image, display the ROI, wait for the user to change/validate it and continue with the next image.

I tried this:

if(manualCorrection){
	ImagePlus ip = currentImage.duplicate();
	ip.show();
	ip.setRoi(new PolygonRoi(roiA[index].getConvexHull(), Roi.POLYGON));
	new WaitForUserDialog("Correct the ROI").show();			
	ip.hide(); ip.close(); ip.flush();
}

But all I see is the frame of the image (the image is not displayed) and the frame of the WaitForUserDialog, but the not t he message. When I click "OK", nothing happens...

Following this postI tried this:
 
if(manualCorrection){
	ImagePlus ip = currentImage.duplicate();
	ip.show();
	ip.setRoi(new PolygonRoi(roiA[index].getConvexHull(), Roi.POLYGON));
	Thread waitDialog = new Thread(new Runnable() {
			public void run() {		 			
		new WaitForUserDialog("Correct the ROI").show();
		}
	});
	waitDialog.start();			
	ip.hide(); ip.close(); ip.flush();
}

But it did not work either. ImageJ does not wait for the user to click OK and the images and messages are only displayed when the loop is finished...

Any ideas?