Login  Register

Re: IJ.doCommand(???) and ThresholdAdjuster

Posted by Carl Trapani - SkyTop Software on Aug 13, 2008; 8:48pm
URL: http://imagej.273.s1.nabble.com/IJ-doCommand-and-ThresholdAdjuster-tp3695389p3695391.html

Wayne Rasband wrote:
> Use the Plugins>Utilities>List Commands (or Find Commands in v1.41)
> command to get a list of all the menu commands. You can also get a
> command name by running the command with the recorder running.

Excellent! Thanks Wayne. Thanks also for an amazing tool!

> Both IJ.run() and IJ.doCommand() run the specified command but
> IJ.run() does not return until the command finishes whereas
> IJ.doCommand() runs the command in a separate thread and returns
> immediately. You can use use either IJ.run("Threshold...") or
> IJ.doCommand("Threshold...") to open the Threshold window.
>
> -wayne

For anyone else out there, here is a code snippet that may be useful (or
may not). It appears that the buttons for ThresholdAdjuster are inside a
panel:

ThresholdAdjuster ta =
(ThresholdAdjuster)IJ.runPlugIn(ThresholdAdjuster.class.getName(), null);
//Now I have a reference to ThresholdAdjuster
Component[] comps = ta.getComponents();
IJ.write("There are " + comps.length + " components in ThresholdAdjuster.");
for (Component c : comps) {
    IJ.write("Component " + c.getName());
    if (c instanceof Button) {
        Button b = (Button) c;
        b.setVisible(false);
        IJ.write("Found Button " + b.getLabel() + " and
setVisible(false).");
    }
    else if (c instanceof JButton) {
        JButton b = (JButton) c;
        b.setVisible(false);
        IJ.write("Found Button " + b.getText() + " and setVisible(false).");
    }


Output:
There are 7 components in ThresholdAdjuster.
Component canvas0
Component scrollbar0
Component label0
Component scrollbar1
Component label1
Component choice0
Component panel0

Carl Trapani