DateTimeLabel
DateTimeLabel is a simple Vaadin add-on which extends normal Vaadin Label and displays a date/time on it and periodically updates it using client side timer.
DateTimeLabel is a simple Vaadin add-on which extends normal Vaadin Label and displays a date/time on it and periodically updates it.
A client side timer is used in updating. The date/time formatter and the update interval can be configured.
Sample code
// Default use, example result label contents e.g. // Thu Feb 06 15:41:39 GMT+200 2014 // Updated every second DateTimeLabel dateTimeLabel1 = new DateTimeLabel(); // Example where update interval is set to 5s and custom date format is specified. // See GWT DateTimeFormat for format string specification: // http://www.gwtproject.org/javadoc/latest/com/google/gwt/i18n/client/DateTimeFormat.html // Resulting label contents e.g. Wed Feb 12 12:29 2014 DateTimeLabel dateTimeLabel2 = new DateTimeLabel(5 * 1000, "EEE MMM d HH:mm yyyy"); // Add to layout etc.
import com.vaadin.server.VaadinRequest; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.CssLayout; import com.vaadin.ui.TextField; import com.vaadin.ui.UI; import com.nextfour.datetimelabel.DateTimeLabel; @SuppressWarnings("serial") public class DatetimelabelUI extends UI { @Override protected void init(VaadinRequest request) { // Create new DateTimeLabel final DateTimeLabel dateTimeLabel = new DateTimeLabel(); CssLayout layout = new CssLayout(); final TextField tf1 = new TextField("Refresh interval (ms):"); final TextField tf2 = new TextField("Format (leave empty for default):"); Button updateButton = new Button("Update"); updateButton.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { try { dateTimeLabel.setRefreshIntervalMs(Integer.parseInt(tf1 .getValue())); } catch (NumberFormatException e) { dateTimeLabel.setRefreshIntervalMs(1000); } dateTimeLabel.setDateFormat(tf2.getValue()); } }); layout.addComponent(tf1); layout.addComponent(tf2); layout.addComponent(updateButton); layout.addComponent(dateTimeLabel); setContent(layout); } }
Links
Compatibility
Was this helpful? Need more help?
Leave a comment or a question below. You can also join
the chat on Discord or
ask questions on StackOverflow.
Version
Initial release.
- Released
- 2014-02-12
- Maturity
- BETA
- License
- Apache License 2.0
Compatibility
- Framework
- Vaadin 7.1+
- Browser
- Browser Independent
DateTimeLabel - Vaadin Add-on Directory
DateTimeLabel is a simple Vaadin add-on which extends normal Vaadin Label and displays a date/time on it and periodically updates it using client side timer.DateTimeLabel is a simple Vaadin add-on which extends normal Vaadin Label and displays a date/time on it and periodically updates it.
A client side timer is used in updating. The date/time formatter and the update interval can be configured.