Java JPasswordField set echo char

Introduction

Setting echo character to zero as follows will show the password

// Set the echo character to 0, so the actual password characters are visible.
passwordField.setEchoChar((char)0);
import java.awt.FlowLayout;

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

class Demo extends JPanel {
  public Demo() {    
    setLayout(new FlowLayout());
    //from  w ww  .  j a v a2 s  .  c o  m
    JPasswordField passwordField = new JPasswordField(10);
    passwordField.setEchoChar('#');
    add(passwordField);
  }
}

public class Main {
  public static void main(String[] args) {
    Demo panel = new Demo();
    JFrame application = new JFrame();
    application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    application.add(panel);
    application.setSize(250, 250);
    application.setVisible(true);
  }
}



PreviousNext

Related