Once the dialog is not needed, you can call ReleaseGUIObject to dispose of the instance.
The following variants also show different techniques for defining a reusable progress dialog within the layout of an AddOn, and discuss the many options available for exposing only a subset of the properties and widgets that make up the user interface.
In this version, you postmanipulate the Java objects in the Wolfram Language by looking up the instances from their names after loading the definition file. After modifying the frame's title and the label's text, you will then call GUIRun, which displays the dialog.
Here is a function that simulates a typical interaction with the GUIObject representing a progress bar dialog.
To use the progress bar in a computation, you call CreateProgressBar1, which loads the user interface definition and returns a GUIObject. Then, while the computation is running, you periodically change the value property to update the bar's appearance. When the computation is done, you call ReleaseGUIObject.
This example illustrates how you can alternatively create reusable versions of a progress bar or any widget by placeholding dynamic properties that may need to change for each instance. This is done by using WidgetReference["#n"] within a base .m and creating various wrapper .m files that define these needed arguments to the base script externally.
In this example, you use a base user interface called ProgressBar2Base.m that contains uses of WidgetReference["#n"] and expects these values to be passed as initial arguments when called.
The source of ProgressBar2Base.m clarifies what dynamic elements of the progress bar are unique to this instance by only exposing certain properties within ProgressBar2Base.m, but setting all these modifiable properties within the wrapping .m file.
Taking this wrapper and base .m a step further, the Wolfram Language functions that load and run GUIObject instances can also pass script arguments when they are called using an optional second argument. Here you show how the Wolfram Language code can dynamically pass arguments to the base .m file that you used previously, duplicating the functionality of example 1, but greatly simplifying the interaction with the reusable user interface by not seeing all the individual property processing calls within the CreateProgressBar1 Wolfram Language code.
Notice how the second argument to GUILoad is simply , which will be registered in the widget name registry as , , and , respectively.
The two-argument call to GUILoad using ProgressBar2Base.m is the equivalent of example 2A of wrapping ProgressBar2Base.m with ProgressBar2.m containing the values desired.