gwt
DateTimePicker
With this example we are going to demonstrate how to create a Date time Picker using the Google Web Toolkit, that is an open source set of tools that allows web developers to create and maintain complex JavaScript front-end applications in Java. In short, to create a Date Time picker we have followed the steps below:
- The
DateTimePickerExample
class implements thecom.google.gwt.core.client.EntryPoint
interface to allow the class to act as a module entry point. It overrides itsonModuleLoad()
method. - Create a Label widget.
- Create new DateBox. Set date format to the dateBox.
- Create a new VerticalPanel and add the DateBox and the Label to it.
- Add the VerticalPanel to the
RootPanel
, that is the panel to which all other widgets must ultimately be added.
Let’s take a look at the code snippet that follows:
package com.javacodegeeks.snippets.enterprise; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.i18n.client.DateTimeFormat; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.user.datepicker.client.DateBox; public class DateTimePickerExample implements EntryPoint { @Override public void onModuleLoad() { Label label = new Label("Click to choose date/time :"); // Define date format DateTimeFormat dateFormat = DateTimeFormat.getFullDateTimeFormat(); // Create new DateBox DateBox dateBox = new DateBox(); // Set date format to the dateBox dateBox.setFormat(new DateBox.DefaultFormat(dateFormat)); // Create new Vertical Panel VerticalPanel vp = new VerticalPanel(); // Add widgets to Verical Panel vp.add(label); vp.add(dateBox); // Add Vertical Panel to Root Panel RootPanel.get().add(vPanel); } }
This was an example of how to create a Date Time picker.