Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
A development toolkit for making RICH Internet Applications(RIA) is called Google Web Toolkit (GWT). It gives programmers the option to create client-side Java applications. The Java code is converted to JavaScript code via GWT.
A typical single-line text box is represented by the TextBox widget. ValueBoxBase.setDirectionEstimator(boolean) has control over this functionality. When at least one of the application's locales is right-to-left, this method is automatically available. Calling new TextBox() constructor without any parameters will generate the instance().
Determines the text box's maximum number of visible characters.
7.
static TextBox wrap(Element element)
Creates a TextBox widget that encloses an <input type='text'> element that already exists.
GWT TextBox Widget Example
This example will walk you through some straightforward GWT TextBox Widget usage instructions. To upgrade the GWT application we developed in GWT, follow these steps:
Step 1: Project Creation👨💻
Create a project with the name GWTTextBox.
Step 2: Modification in Files👨🔧
Modify the ‘GWTTextBox.gwt.xml’, ‘GWTTextBox.css’, ‘GWTTextBox.html’, and ‘GWTTextBox.java’ files as explained below. Keep the rest of the files unchanged.
Step 3: Check the Result🤳🏼
Compile and run the application to check your results.
The changed module description, located at ‘src/com.codingninjas.gwttextbox/GWTTextBox.gwt.xml’, contains the content given below:
<? xml version = "1.0" encoding = "UTF-8" ?>
<module rename-to='gwttextbox'>
<inherits name='com.google.gwt.user.User' />
<!-- for default stylesheet, you can add any style to your project-->
<!-- <inherits name='com.google.gwt.user.theme.clean.Clean' /> -->
<entry-point class='com.codingninjas.gwttxtb.client.GWTTextBox' />
<source path='client' />
<source path='shared' />
<!-- allow Super Dev Mode -->
<add-linker name="xsiframe" />
</module>
Now write some styling in the CSS file for your project which is located at ‘war/GWTTextBox.css’.
body {
text - align: center;
font - family: verdana, sans - serif;
}
h1 {
font - size: 3em;
font - weight: bold;
color: #004080;
margin: 30px 0px 80px;
text - align: center;
}
.gwt - TextBox {
color: yellow;
}
.gwt - TextBox - readonly {
background - color: blue;
}
Now write in the HTML host file for your project which is located at war/GWTTextBox.html.
The Java file ‘src/com.codingninjas.gwttextbox/GWTTextBox.java’ with the following contents will show how to utilize the PushButton widget.
In the above example, we can see there are two text boxes in which one is disabled and the other one is enabled to take inputs. In the disabled text box, the text is already passed as “Welcome to Coding Ninjas!” and set as ReadOnly.
package com.codingninjas.gwttxtb;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.RootPanel;
public class GWTTextBox implements EntryPoint {
public void onModuleLoad() {
/*
To make the textBox
*/
TextBox txtBox1 = new TextBox();
TextBox txtBox2 = new TextBox();
/*
To set the text into your textBox
*/
txtBox2.setText("Welcome to Coding Ninjas!");
/*
Now setting textBox as 'readOnly'
*/
txtBox2.setReadOnly(true);
/*
Adding the textBox to the 'RootPanel'
*/
VerticalPanel panel = new VerticalPanel();
panel.setSpacing(10);
panel.add(txtBox1);
panel.add(txtBox2);
RootPanel.get("handleDiv").add(panel);
}
}
You can also try this code with Online Java Compiler
When you are finished and have made all the necessary modifications, compile and run the application in development mode.
This will get the results as shown below:
In the above example, we can see there are two text boxes in which one is disabled and the other one is enabled to take inputs. In the disabled text box, the text is already passed as “Welcome to Coding Ninjas!” and set as ReadOnly.
Frequently Asked Questions
What do you mean by GWT RPC(Remote Procedure Call)?
Your web application's client and server components can easily exchange Java objects over HTTP thanks to the GWT RPC framework.
What do you mean by GWT language?
GWT is nothing but Java to JavaScript compiler. It Creates a JavaScript equivalent for the Java programming language.
What we have to write in GWT XML file?
The actual list of Java classes and other resources that are included in the GWT module is specified in the gwt.xml file.
Can we call GWT as framework?
An open source Java software development platform called Google Web Toolkit (GWT) makes it simple to create AJAX apps.
What do you mean by GWT.create()?
It is used by GWT compiler for deferred binding.
Conclusion
In this article, we have discussed the GWT TextBox Widget. We have discussed its constructors, methods, and implementation. GWT TextBox Widget is a part of form widgets that are used in many places while developing applications.