GWT - PasswordTextBox Widget



The PasswordTextBox widget represents a standard single-line text box that visually masks its input to prevent eavesdropping.

Class Declaration

Following is the declaration for class −

public class PasswordTextBox
   extends TextBox

CSS Style Rules

Following default CSS Style rules will be applied to all the PasswordTextBox widget. You can override it as per your requirements.

.gwt-PasswordTextBox {}

.gwt-PasswordTextBox-readonly {} 

Class Constructors

Sr.No. Constructor & Description


Creates an empty password text box.


PasswordTextBox(Element element)

This constructor may be used by subclasses to explicitly use an existing element.

Class Methods

Sr.No. Function name & Description

static PasswordTextBox wrap(Element element)

Creates a PasswordTextBox widget that wraps an existing <input type='password'> element.

Methods Inherited

This class inherits methods from the following classes −






  • java.lang.Object

PasswordTextBox Widget Example

This example will take you through simple steps to show usage of a PasswordTextBox Widget in GWT. Follow the following steps to update the GWT application we created in GWT - Create Application chapter −

Step Description
1 Create a project with a name HelloWorld under a package com.tutorialspoint as explained in the GWT - Create Application chapter.
2 Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorld.html and as explained below. Keep rest of the files unchanged.
3 Compile and run the application to verify the result of the implemented logic.

Following is the content of the modified module descriptor src/com.tutorialspoint/HelloWorld.gwt.xml.

<?xml version = "1.0" encoding = "UTF-8"?>
<module rename-to = 'helloworld'>
   <!-- Inherit the core Web Toolkit stuff.                        -->
   <inherits name = ''/>

   <!-- Inherit the default GWT style sheet.                       -->
   <inherits name = ''/>

   <!-- Specify the app entry point class.                         -->
   <entry-point class = 'com.tutorialspoint.client.HelloWorld'/>

   <!-- Specify the paths for translatable code                    -->
   <source path = 'client'/>
   <source path = 'shared'/>


Following is the content of the modified Style Sheet file war/HelloWorld.css.

body {
   text-align: center;
   font-family: verdana, sans-serif;

h1 {
   font-size: 2em;
   font-weight: bold;
   color: #777777;
   margin: 40px 0px 70px;
   text-align: center;

.gwt-PasswordTextBox {
   color: green; 

.gwt-PasswordTextBox-readonly {
   background-color: yellow;	

Following is the content of the modified HTML host file war/HelloWorld.html.

      <title>Hello World</title>
      <link rel = "stylesheet" href = "HelloWorld.css"/>
      <script language = "javascript" src = "helloworld/helloworld.nocache.js">

      <h1>PasswordTextBox Widget Demonstration</h1>
      <div id = "gwtContainer"></div>

Let us have following content of Java file src/com.tutorialspoint/ which will demonstrate use of PasswordTextBox widget.

package com.tutorialspoint.client;


public class HelloWorld implements EntryPoint {
   public void onModuleLoad() {
      //create password textboxes
      PasswordTextBox passwordTextBox1 = new PasswordTextBox(); 
      PasswordTextBox passwordTextBox2 = new PasswordTextBox();

      //add text to text box

      //set textbox as readonly

      // Add text boxes to the root panel.
      VerticalPanel panel = new VerticalPanel();


Once you are ready with all the changes done, let us compile and run the application in development mode as we did in GWT - Create Application chapter. If everything is fine with your application, this will produce following result −

GWT PasswordTextBox Widget