HOW TO: JProgressbar bean

Find out how to get things done with Servoy. Post how YOU get things done with Servoy

HOW TO: JProgressbar bean

Postby maarten » Fri Feb 13, 2004 11:26 am

1) go into designer and place a JProgessbar bean in your form
2) set name property to "progress"
3) create script with this code:

Code: Select all
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.
Maarten Berkenbosch
User avatar
maarten
 
Posts: 797
Joined: Wed Apr 23, 2003 10:52 pm
Location: Amersfoort, Netherlands

Postby IT2Be » Fri Feb 13, 2004 12:57 pm

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...
Marcel J.G. Trapman (IT2BE)
SAN partner - Freelance Java and Servoy
Servoy Components - IT2BE Plug-ins and Beans for Servoy
ServoyForge - Open Source Components for Servoy
User avatar
IT2Be
Servoy Expert
 
Posts: 4766
Joined: Tue Oct 14, 2003 7:09 pm
Location: Germany

Postby patrick » Fri Feb 13, 2004 2:11 pm

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.
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Postby IT2Be » Fri Feb 13, 2004 2:13 pm

What version do you use?
Marcel J.G. Trapman (IT2BE)
SAN partner - Freelance Java and Servoy
Servoy Components - IT2BE Plug-ins and Beans for Servoy
ServoyForge - Open Source Components for Servoy
User avatar
IT2Be
Servoy Expert
 
Posts: 4766
Joined: Tue Oct 14, 2003 7:09 pm
Location: Germany

Postby patrick » Fri Feb 13, 2004 2:25 pm

rc6
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Postby maarten » Fri Feb 13, 2004 2:54 pm

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.
Maarten Berkenbosch
User avatar
maarten
 
Posts: 797
Joined: Wed Apr 23, 2003 10:52 pm
Location: Amersfoort, Netherlands

Postby patrick » Fri Feb 13, 2004 3:00 pm

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
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Postby IT2Be » Fri Feb 13, 2004 3:10 pm

Maarten, I don't have an issue (rc6) but do work with mac os :)
Marcel J.G. Trapman (IT2BE)
SAN partner - Freelance Java and Servoy
Servoy Components - IT2BE Plug-ins and Beans for Servoy
ServoyForge - Open Source Components for Servoy
User avatar
IT2Be
Servoy Expert
 
Posts: 4766
Joined: Tue Oct 14, 2003 7:09 pm
Location: Germany

Postby maarten » Fri Feb 13, 2004 5:46 pm

hmm, unfortunately :wink: keeps working on my machine.
(rc6, W2000, java 1.4.1)
What java version are you running Patrick?
Maarten Berkenbosch
User avatar
maarten
 
Posts: 797
Joined: Wed Apr 23, 2003 10:52 pm
Location: Amersfoort, Netherlands

Postby patrick » Fri Feb 13, 2004 6:03 pm

Java version 1.4.2_03-b02 (Windows XP)

Thanks for investigating.
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Postby WiderGates » Sat Feb 14, 2004 1:00 am

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
Version R2 2.0 rc8-build 267; Java version 1.4.2_03-b02 (Windows 2000)

Dieter Jekal
WiderGates
WiderGates
 
Posts: 37
Joined: Thu Aug 28, 2003 9:46 am
Location: Schnaittenbach, Germany

Postby IT2Be » Sat Feb 14, 2004 11:48 am

Do you set the value to 0 somewhere?
Marcel J.G. Trapman (IT2BE)
SAN partner - Freelance Java and Servoy
Servoy Components - IT2BE Plug-ins and Beans for Servoy
ServoyForge - Open Source Components for Servoy
User avatar
IT2Be
Servoy Expert
 
Posts: 4766
Joined: Tue Oct 14, 2003 7:09 pm
Location: Germany

Postby WiderGates » Sat Feb 14, 2004 12:19 pm

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 ?
Version R2 2.0 rc8-build 267; Java version 1.4.2_03-b02 (Windows 2000)

Dieter Jekal
WiderGates
WiderGates
 
Posts: 37
Joined: Thu Aug 28, 2003 9:46 am
Location: Schnaittenbach, Germany

Postby patrick » Sat Feb 14, 2004 12:29 pm

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...
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Postby IT2Be » Sat Feb 14, 2004 12:53 pm

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:

1. create a global variable globals.buttonwasclicked
2. when you start the method execute the following:
Code: Select all
if (globals.buttonwasclicked) return;
globals.buttonwasclicked = true

3. at the end of the loop:
Code: Select all
buttonwasclicked = false;
Marcel J.G. Trapman (IT2BE)
SAN partner - Freelance Java and Servoy
Servoy Components - IT2BE Plug-ins and Beans for Servoy
ServoyForge - Open Source Components for Servoy
User avatar
IT2Be
Servoy Expert
 
Posts: 4766
Joined: Tue Oct 14, 2003 7:09 pm
Location: Germany

Next

Return to How To

Who is online

Users browsing this forum: No registered users and 12 guests