I want to create a JPasswordField
where I can see the characters while typing,
I tried passtxt.setEchoChar((char) 0);
but it completely change the '*'
to text
I don't want this,
I want to view text while typing character by character
( as we see in mobile browsers)
thanks
import java.awt.BorderLayout;
import java.awt.Checkbox;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.Box;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class Main {
public static void main(String args[]) {
JFrame f = new JFrame("JPasswordField ");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel p=new JPanel();
p.add(new JLabel("Username"));
p.add(new JTextField(20));
p.add(new JLabel("Password"));
JPasswordField jpassword = new JPasswordField(20);
p.add(jpassword);
Checkbox c=new Checkbox("type password and click");
c.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
jpassword.setEchoChar('*');
} else {
jpassword.setEchoChar((char) 0);
}
}
});
jpassword.setEchoChar((char)0);
p.add(c);
f.add(p);
f.setSize(300, 200);
f.setVisible(true);
}
}