gwt
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 thecom.google.gwt.core.client.EntryPoint
interface to allow the class to act as a module entry point. It overrides itsonModuleLoad()
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 { @Override public void onModuleLoad() { //Create new Vertical Panel and set spacing VerticalPanel vp = new VerticalPanel(); vp.setSpacing(10); //Regular text box //Create new Horizontal panel and add regular text box and label HorizontalPanel hpReg = new HorizontalPanel(); hpReg.setSpacing(3); Label regLabel = new Label("Regular Text Box :"); TextBox regText = new TextBox(); hpReg.add(regLabel); hpReg.add(regText); //Disabled text box (read only) //Create new Horizontal panel and add disabled text box and label HorizontalPanel hpDis = new HorizontalPanel(); hpDis.setSpacing(3); Label disLabel = new Label("Disabled Text Box :"); TextBox disText = new TextBox(); //Set it disabled disText.setEnabled(false); disText.setText("Read only"); hpDis.add(disLabel); hpDis.add(disText); //Password text box //Create new Horizontal panel and add password text box and label HorizontalPanel hpPass = new HorizontalPanel(); hpPass.setSpacing(3); Label passLabel = new Label("Password Text Box :"); PasswordTextBox passText = new PasswordTextBox(); hpPass.add(passLabel); hpPass.add(passText); //Text Area //Create new Horizontal panel and add text area and label HorizontalPanel hptArea = new HorizontalPanel(); hptArea.setSpacing(3); Label tAreaLabel = new Label("Text Area Box:"); TextArea tArea = new TextArea(); hptArea.add(tAreaLabel); hptArea.add(tArea); //Add Horizontal Panels to Vertical Panel vp.add(hpReg); vp.add(hpDis); vp.add(hpPass); vp.add(hptArea); // Add Vertical Panel to Root Panel RootPanel.get().add(vp); } }
This was an example of how to create a Text input example, using the Google Web Toolkit.