Constructors of GWT PasswordTextBox🧑🏻💻
The GWT PasswordTexBox widget comes equipped with various constructors. Let us discuss some of these in this section,
- PasswordTextBox() - This constructor creates an empty text box of password.
- PasswordTextBox(Element element) - Subclass uses this constructor for explicitly use existing elements.
Methods of GWT PasswordTextBox🧑🏻💻
The GWT PasswordTexBox widget has only one class method. Let us look at the GWT PasswordTexBox widget methods,
- static PasswordTextBox wrap(Element element) - A PasswordTextBox widget which wraps existing <input type='password'> element is created by this method.
Inherited Methods🤘🏻
The GWT PasswordTextBox Widget inherits the following Java classes,
- com.google.gwt.user.client.ui.UIObject
- com.google.gwt.user.client.ui.TextBoxBase
- com.google.gwt.user.client.ui.FocusWidget
- com.google.gwt.user.client.ui.TextBox
- com.google.gwt.user.client.ui.Widget
- java.lang.Object
GWT PasswordTextBox Widget Example💻
In this section, we will go through the simple steps to show the usage of the GWT PasswordTextBox Widget. Here you need to modify files ‘GWTProjectOne.css’, ‘GWTProjectOne.gwt.xml’, ‘GWTProjectOne.html’, and ‘GWTProjectOne.java’ by changing the code with the below code.
The Eclipse IDE and file structure will look something like this -


GWTProjectOne.gwt.xml
<?xml version = "1.0" encoding = "UTF-8"?>
<module rename-to = 'gwtprojectone'>
<!-- Let's inherit the core GWT things. -->
<inherits name = 'com.google.gwt.user.User'/>
<!-- Let's inherit the default Google Web Toolkit style sheet. -->
<inherits name = 'com.google.gwt.user.theme.clean.Clean'/>
<!-- Let's specify the application entry-point class. -->
<entry-point class = 'coding.ninja.client.GWTProjectOne'/>
<!-- Let's specify the source paths for the translatable code. -->
<source path = 'client'/>
<source path = 'shared'/>
<add-linker name="xsiframe"/>
<set-configuration-property name="devModeRedirectEnabled" value="true"/>
<!-- enable source maps -->
<set-property name="compiler.useSourceMaps" value="true" />
</module>
GWTProjectOne.css
body {
text-align: center;
font-family: Inter, sans-serif;
}
h1 {
font-size: 2em;
font-weight: bold;
color: #6907E6;
margin: 40px 0px 70px;
text-align: center;
}
.gwt-PasswordTextBox {
color: orange;
}
.gwt-PasswordTextBox-readonly {
background-color: black;
}
GWTProjectOne.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="GWTProjectOne.css">
<script type="text/javascript" language="javascript" src="gwtprojectone/gwtprojectone.nocache.js"></script>
</head>
<body>
<h1>Coding Ninjas PasswordTextBox Widget</h1>
<div id = "CodingContainer"></div>
</body>
</html>
GWTProjectOne.java
package coding.ninja.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
public class GWTProjectOne implements EntryPoint {
public void onModuleLoad() {
PasswordTextBox passwordTextBox1 = new PasswordTextBox();
PasswordTextBox passwordTextBox2 = new PasswordTextBox();
passwordTextBox2.setText("hell@Ninj@s");
passwordTextBox2.setReadOnly(true);
VerticalPanel panel = new VerticalPanel();
panel.setSpacing(10);
panel.add(passwordTextBox1);
panel.add(passwordTextBox2);
RootPanel.get("codingNinjas").add(panel);
}
}

You can also try this code with Online Java Compiler
Run Code
After modifying all the files, right-click the project, go to GWT and then select compile button, and then you will see one dialog box where you have again click on compile button.


And after clicking it, you will see the following output in the console.

Now click on the dropdown button of the run button and select the project you want to run that is, in our case, GWTProjectOne.

After clicking, you will see the following outputs in the console and development mode tab.

After clicking on the link in development mode, you will see the output of the code.

Output
Here we have two password text boxes. We have a password text box (passwordTextBox1) where we can type our password.

In the other password text box (passwordTextBox2), we have set the default value as "hell@Ninj@s" which is masked in the output, and we have set the .setReadOnly() property to the "true" value.

We hope you have completely understood the GWT PasswordTextBox Widget. 😁
Frequently Asked Questions
What is the google web toolkit?
GWT (Google web toolkit) is an open-source development toolkit provided by google for developing browser-based, complex Ajax applications.
What is an IDE?
IDE is an integrated development environment. It is a software application that provides comprehensive facilities to programmers for software development.
What is JDK?
JDK is a java development kit. It is the distribution of java technology by oracle corporation. It implements java virtual and Java language specifications.
What is the advantage of developing a web application in GWT?
We can develop GWT apps in Java, and the advantages of developing in Java are auto-complete, refactoring, debugging, code reuse, etc.
What are the tools used by Java for development?
Java's development tools are Netbeans, Eclipse, JUnit, Maven, etc., also used to develop Rich Internet Applications.
Conclusion
In this blog, we went through GWT PasswordTextBox Widget. We saw class declaration, CSS style rules, constructors, and inherited methods. At last, we will see an example of the GWT PasswordTextBox Widget and if you want to learn more, check out our articles on-
Refer to our guided paths on Coding Ninjas Studio to learn more about DSA, Competitive Programming, JavaScript, System Design, etc. Enroll in our courses and refer to the mock test and problems available. Take a look at the interview experiences and interview bundle for placement preparations.
Do upvote our blog to help other ninjas grow.

Happy Learning Ninja! 🥷