import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
public class Test extends JFrame {
public Test() {
setSize(300, 300);
setLocationRelativeTo(null);
setDefaultCloseOperation(3);
JPanel p = new JPanel();
final JPasswordField pwd = new JPasswordField();
pwd.setPreferredSize(new Dimension(200, 25));
pwd.setEchoChar('*');
final JCheckBox chk = new JCheckBox();
chk.setText("Show password");
chk.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(chk.isSelected())
pwd.setEchoChar((char)0);
else
pwd.setEchoChar('*');
}
});
p.add(pwd);
p.add(chk);
setContentPane(p);
}
public static void main(String[] args) {
new Test().setVisible(true);
}
}