Home » Enterprise Java » gwt » Text Input Example

About 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.

Text Input Example

This is an example of how to create a Text input example, 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. To create a Text input we have followed the steps below:

  • The TextInputExample 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.
  • We create a new Vertical Panel and set its spacing.
  • We create a new Regular TextBox. We create a new Horizontal panel and add the regular text box and Label to it.
  • We also create a read only text box. We create another Horizontal panel and add the disabled text box and a label to it.
  • We create a Password text box. Then we also create a new Horizontal panel and add the password text box and a label to it.
  • We create a Text Area. Then we create a new Horizontal panel and add the text area and a label to it.
  • We add the Horizontal Panels to the Vertical Panel and then add the Vertical Panel 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.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

public class TextInputExample implements EntryPoint {

	public void onModuleLoad() {
		//Create new Vertical Panel and set spacing
		VerticalPanel vp = new VerticalPanel();
		//Regular text box
		//Create new Horizontal panel and add regular text box and label 
		HorizontalPanel hpReg = new HorizontalPanel();
		Label regLabel = new Label("Regular Text Box :");
		TextBox regText = new TextBox();
		//Disabled text box (read only)
		//Create new Horizontal panel and add disabled text box and label 
		HorizontalPanel hpDis = new HorizontalPanel();
		Label disLabel = new Label("Disabled Text Box :");
		TextBox disText = new TextBox();
		//Set it disabled
		disText.setText("Read only");
		//Password text box
		//Create new Horizontal panel and add password text box and label 
		HorizontalPanel hpPass = new HorizontalPanel();
		Label passLabel = new Label("Password Text Box :");
		PasswordTextBox passText = new PasswordTextBox();
		//Text Area
		//Create new Horizontal panel and add text area and label 
		HorizontalPanel hptArea = new HorizontalPanel();
		Label tAreaLabel =  new Label("Text Area Box:");
		TextArea tArea = new TextArea();
		//Add Horizontal Panels to Vertical Panel
		// Add Vertical Panel to Root Panel

This was an example of how to create a Text input example, using the Google Web Toolkit.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!


1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design


and many more ....


Receive Java & Developer job alerts in your Area

I have read and agree to the terms & conditions


Notify of

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

Inline Feedbacks
View all comments