Progress bar
The WProgressBar can be used to indicate the progress of a
certain operation. The text displayed in the progress bar can be
customized by specializing text()
.
To use the progress bar widget, you need to give it a range (either by
setRange()
or by using setMinimum()
and
setMaximum()
), and update the progress using setValue()
.
Example
source
void ProgressBar () {
WContainerWidget container = new WContainerWidget ();
container . setStyleClass ( "inline-buttons" );
final WProgressBar bar = new WProgressBar (( WContainerWidget ) container );
bar . setRange ( 0 , 10 );
final WPushButton startButton = new WPushButton ( "Start" , ( WContainerWidget ) container );
final WPushButton stopButton = new WPushButton ( "Stop" , ( WContainerWidget ) container );
final WPushButton resetButton = new WPushButton ( "Reset" , ( WContainerWidget ) container );
stopButton . disable ();
resetButton . disable ();
final WTimer intervalTimer = new WTimer ();
intervalTimer . setInterval ( Duration . ofMillis ( 1000 ));
startButton
. clicked ()
. addListener (
this ,
() -> {
if ( bar . getValue () < 10 ) {
intervalTimer . start ();
startButton . setText ( "Resume" );
}
startButton . disable ();
stopButton . enable ();
resetButton . disable ();
});
stopButton
. clicked ()
. addListener (
this ,
() -> {
intervalTimer . stop ();
startButton . enable ();
stopButton . disable ();
resetButton . enable ();
});
resetButton
. clicked ()
. addListener (
this ,
() -> {
bar . setValue ( 0.0 );
startButton . setText ( "Start" );
startButton . enable ();
stopButton . disable ();
resetButton . disable ();
});
intervalTimer
. timeout ()
. addListener (
this ,
() -> {
bar . setValue ( bar . getValue () + 1 );
if ( bar . getValue () == 10 ) {
stopButton . clicked (). trigger ( new WMouseEvent ());
startButton . disable ();
}
});
}
Remark
With the advent of HTML5, this widget will be implemented using the
native HTML5 control when available.
Top