go into designer and place a JProgessbar bean in your form
set name property to “progress”
create script with this code:
elements.progress.visible = true // show progress bar
elements.progress.orientation = 0 //(0=hor(default) 1=vertical)
elements.progress.stringPainted = true // enables showing strings inside the progres bar
elements.progress.string = "Starting script..."
elements.progress.value =0 // initialise value of the progres bar
elements.progress.minimum = 0 // min value allowed
elements.progress.maximum = 1000 //max value allowed
var percentage =0
for (var i=0 ; i<1000 ; i++)
{
elements.progress.value = i
//application.sleep(10)//simulates time needed to perform a loop
percentage = elements.progress.getPercentComplete()
elements.progress.string = "Looped through "+i+" records.Completed "+parseInt(percentage*100)+"%. "
application.updateUI() //refresh user interface
}
elements.progress.string = "Script Completed"
application.beep()//signal when ended
application.sleep(1000) // bar remains visible 1 more second before disappearing
elements.progress.visible= false
plugins.dialogs.showInfoDialog( '', 'Script completed', 'OK')
I think this was discussed before: I place the bean on my form, try your script, get an error and then realize, that the bean has disappeared from the elements in the method editor. I can still see it on the form but it cannot be addressed. This seems to happen every time you switch from designer to browse mode and back.
Maybe the porblem is the kind of form: I am trying to use this in a table view. First I placed the bean in the title header, then in the body part. No difference…
Runs really good, but when I do it in ListView the progressbar is about 50 times slower than in RecordView. Why ?
I have asigned this method to an onAction of a button. When I klick the bar itM-4s running and when I klick again, while the bar is running it starts over from the beginning. How can I avoid this ?
I still have that bean problem: you can see the bean on the form, but it doesn’t appear under elements in the methode editor. Once I got it to work, though. But after switching between desinger and browse mode, it disappeared again…
Wider: If you execute the method like above you have your answers to both your questions:
By clicking the button you really start over at 0 again since the loop starts at 0 and the value of the progressbar is taken from the loop…
Yes clicking a button executes the method attached to it. If you don’t want to do such a thing you should check if the button was clicked. You can do this by:
create a global variable globals.buttonwasclicked
when you start the method execute the following:
if (globals.buttonwasclicked) return;
globals.buttonwasclicked = true
I have posted a module that uses the JProgressBar bean to display a progress indicator in a non-modal dialog. This approach makes it possible to display and update the progress indicator by placing a single call inside the loop that is driving your lengthy process. This is, in my opinion, an improvement over the example at the start of this thread, which used a modal dialog and therefore required that the main processing loop be placed in the onShow method of the form in dialog.
[attachment=0]progress.JPG[/attachment]
The module and accompanying documentation are available here