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 the com.google.gwt.core.client.EntryPoint interface to allow the class to act as a module entry point. It overrides its onModuleLoad() 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.

Byron Kiourtzoglou

Byron is a master software engineer working in the IT and Telecom domains. He is an applications developer in a wide variety of applications/services. He is currently acting as the team leader and technical architect for a proprietary service creation and integration platform for both the IT and Telecom industries in addition to a in-house big data real-time analytics solution. He is always fascinated by SOA, middleware services and mobile development. Byron is co-founder and Executive Editor at Java Code Geeks.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button