Posted by
Michael Schmid on
URL: http://imagej.273.s1.nabble.com/Radial-profile-ext-to-work-with-Macros-tp5005598p5005957.html
Hi Philippe,
you can get a Vector of the TextFields used for number input with
Vector numericFields = gd.getNumericFields();
Assuming that you want a reference to the first numeric field:
TextField tf0 = (TextField)(numericFields.elementAt(0));
Assuming that it should contain the variable 'width' you can use
tf0.setText(Integer.toString(width));
[if 'width' is double, use one of the IJ.d2s functions to convert it to a String]
Note that there is a nasty bug with Java on Mac computers (at least for modal dialogs, probably the same for the NonBlockingGenericDialog): If you do several changes at the same time (within a few milliseconds), only the first one will be shown, the other fields are not updated until the next change. [TextField.getText() correctly shows the new data. This bug does not only affect TextFields but also Checkboxes, etc. Mac users may have noticed that the 'preview' and 'wait' of some ImageJ functions with preview is sometimes displayed incorrectly due to this bug.]
As a workaround, if you want to modify the contents of several TextFields at once, it is advisable to add an 'IJ.wait(100)' statement before the last modification.
Enjoy Christmas time and best wishes for a good New Year!
Michael
________________________________________________________________
On Dec 20, 2013, at 14:26, Philippe CARL wrote:
> Dear Michael,
>
>> when recording, a GenericDialog records the values (including checkbox
>> settings, Choice menu settings) after the user has pressed the 'OK' button.
>> When running the macro, it fills in the values and behaves as if the user
>> had pressed 'OK'.
>> So it won't record pressing any other buttons, and when running the macro
>> it won't simulate pressing any buttons.
>> If this is ok for you, you can add a Panel with an arbitrary number of
>> buttons to the GenericDialog.
>>
> This could actually be fine and work (= code already implemented and
> working)....
>
>> The actionPerformed methods may modify input fields of the GenericDialog,
>> e.g. change the numbers in the numeric fields (getText, setText).
>>
> This is actually my next problem: how am I doing this?
> Let's say I have the following code defining the window:
> NonBlockingGenericDialog gd = new NonBlockingGenericDialog("Radial Profile
> Angle...");
> gd.addStringField("Title: ", title);
> gd.addNumericField("Width: ", width, 0);
> gd.addNumericField("Height: ", height, 0);
> How can I then upon an action performed with a button defined by an added
> Panel change the value shown up in either the "Width: " or "Height: "
> NumericField?
>
> I thank you very much in advance for your answer and wish you a merry
> Christmas and happy NEW Year!!!.
>
> Best regards,
>
> Philippe
>
> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html