Adding a GUI to your macro
Sometimes you may want to try different values for some parameters without having to edit the macro code again and again in order to change the hardcoded variables. The Dialog
functions allow you to build your own user interfaces to query the user for information before running the macro. A dialog is built by calling Dialog.create(title)
and then adding the different elements that compose the user interface: textboxes for strings/numbers, sliders, selection menus, checkboxes, and radio buttons. Once all the elements are in place, we just need to get the user input and proceed with the processing of the macro.
The following code creates a simple dialog and will allow us to explore the possibilities of the dialog building functions with some additional nicety:
// We are using some relatively new functions, so we have to // explicitly forbid this macro from running in old ImageJ versions requires("1.47r"); // Create the main window with its title Dialog.create("This...