Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Clock in MenuBar
Hi!
I'm new to vaadin and trying to write a little sample application.
I want a MenuBar on top with a label displaying the actual time, but it doesn't refresh the itemtext:
public class MainMenuBar extends MenuBar {
private static final long serialVersionUID = -3947292765803416622L;
private MenuItem timeLabel;
public MainMenuBar() {
super();
buildLayout();
}
private void buildLayout() {
setWidth(100, UNITS_PERCENTAGE);
timeLabel = addItem("", null, null);
new TimeSetter().start();
}
class TimeSetter extends Thread {
private Date now;
@SuppressWarnings("deprecation")
@Override
public void run() {
while (true) {
now = new Date(System.currentTimeMillis());
timeLabel.setText(now.toLocaleString());
System.out.println("*** now " + now.toLocaleString());
System.out.println("*** item " + timeLabel.getText());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}
The System.out's are correct. Even if i pass over the menuBar reference to the TimeSetter and do menuBar.requestRepaint(); nothing happens. What can i do?
Thread TimeSetter runs on server side, so data changes like timeLabel cannot be updated on client side with basic Vaadin framework. Fortunately you can handle such issues with add-on ICEPush, ServerPush.
I think the refresher add-on can solve this problem quite easily.
Thanks a lot watt and robby! Both addons look great, i'll try them out later. Pretty cool that you can extend vaadin functionality this easy :)