Thread + ProgressBar
private static final long serialVersionUID = 1L;
private static boolean reverse=false;
@Override
protected void init(VaadinRequest request)
{
final VerticalLayout layout = new VerticalLayout();
layout.setMargin(true);
setContent(layout);
final ProgressBar bar = new ProgressBar(0.0f);
layout.addComponent(bar);
Button button = new Button(" :: Start Thread :: ");
button.addClickListener(new Button.ClickListener() {
private static final long serialVersionUID = 1L;
class WorkThread extends Thread {
@Override
public void run() {
while (true) {
try {
sleep(500);
} catch (InterruptedException e) {}
UI.getCurrent().access(new Runnable() {
@Override
public void run() {
float current = bar.getValue();
if (reverse)
{
bar.setValue(current + 0.10f);
if (current >= 1.0f) {reverse=false;bar.setValue(0.9f);}
}
else
{
bar.setValue(current - 0.10f);
if (current <= 0.0f) {reverse=true;bar.setValue(0.1f);}
}
}
});
}
}
}
@Override
public void buttonClick(ClickEvent event)
{
final WorkThread thread = new WorkThread();
thread.start();
UI.getCurrent().setPollInterval(100);
}
});
layout.addComponent(button);
}