Set password symbol or echo character for JPasswordField

Source code below will show you, how to set symbol that will be use in password field that build using JPasswordField. It also called echo character.

***************************************************************************
COMPLETE SOURCE CODE FOR : SetPasswordSymbol.java
***************************************************************************


import javax.swing.JPasswordField;
import javax.swing.JFrame;

import java.awt.FlowLayout;

public class SetPasswordSymbol
{
public static void main(String[]args)
{
//Create a password field with number of columns equal to 10
JPasswordField passwordField=new JPasswordField(10);

//Set password symbol
//In my case i use *
//You can change for what you want.But make sure it is only one character
//This is because, method setEchoChar receive only one character
passwordField.setEchoChar('*');


//Create a JFrame with title ( Set Password Symbol )
JFrame frame=new JFrame("Set Password Symbol");

//Set JFrame layout to FlowLayout
frame.setLayout(new FlowLayout());

//Add password field into JFrame
frame.add(passwordField);

//Set default close operation for JFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Set JFrame size to :
//WIDTH : 300 pixels
//HEIGHT : 65 pixels
frame.setSize(300,65);

//Make JFrame visible. So we can see it
frame.setVisible(true);
}
}


***************************************************************************
JUST COMPILE AND EXECUTE IT
***************************************************************************

RELAXING NATURE VIDEO