HOW TO: JProgressbar bean

  1. go into designer and place a JProgessbar bean in your form
  2. set name property to “progress”
  3. 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')

Have fun.

Just to add a little:

  1. When you set the indeterminate value to true you don’t have to update the values, the progressbar will show a ‘rolling’ bar…

Cheers…

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.

Was there something to do about?

Thanks.

What version do you use?

rc6

which OS are you on?
Does this occur in client and/or developer?

Can anyone else (using rc6) try to reproduce and report please?

Thanks in advance.

I am on Windows XP, using RC6, LAF Windows.

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…

Thanks
Patrick

Maarten, I don’t have an issue (rc6) but do work with mac os :)

hmm, unfortunately :wink: keeps working on my machine.
(rc6, W2000, java 1.4.1)
What java version are you running Patrick?

Java version 1.4.2_03-b02 (Windows XP)

Thanks for investigating.

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 ?

Thanks

Do you set the value to 0 somewhere?

I donM-4t set the value to 0 other than explained.

Is it normal when you click on a button a second time while a method is running, the method is executed a second time ?

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:

  1. 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…

  2. 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:

  3. create a global variable globals.buttonwasclicked

  4. when you start the method execute the following:

if (globals.buttonwasclicked) return;
globals.buttonwasclicked = true
  1. at the end of the loop:
buttonwasclicked = false;

patrick: what kind of bean?

Can you send over a solution that demonstrates this behaviour?

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

Thanks for sharing Adrian!