Clock in MenuBar


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() {

	private void buildLayout() {
		setWidth(100, UNITS_PERCENTAGE);
		timeLabel = addItem("", null, null);
		new TimeSetter().start();

	class TimeSetter extends Thread {

		private Date now;

		public void run() {
			while (true) {
				now = new Date(System.currentTimeMillis());
				System.out.println("*** now  " + now.toLocaleString());
				System.out.println("*** item " + timeLabel.getText());
				try {
				} catch (InterruptedException e) {

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 :slight_smile: