I am using this code to make the key entered in the JPasswordfield "jp_clave" readable by checking the JCheckBox "jcb_key"
private void jcb_claveActionPerformed(java.awt.event.ActionEvent evt) {
jcb_clave.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
jp_clave.setEchoChar((char) 0);
} else {
jp_clave.setEchoChar('*');
}
}
});
The problem is that when running the program I have to check and check the JCheckBox for the first time to work as it should, maybe it is some silly mistake so I ask you to be patient and help me please.
EDITED
Apparently I was giving a lot of laps to the code and thanks to TwoDent my dilemma is solved, regarding the JPasswordField code:
jp_clave = new javax.swing.JPasswordField();
jp_clave.setHorizontalAlignment(javax.swing.JTextField.CENTER);
jp_clave.setText("");
It's all I could track since the code was automatically generated when I dragged the component into the form, by default any text that is written in the pass becomes as if a password was entered and the code in the checkbox (if it was checked) forced to show the text as you typed it