I'm making a Authentication app in java and i want to add a JRadioButton, where if it is selected it will allow you to see the text in the JPasswordField, i was trying to figure it out and i was just wondering is there any way to do it?
Asked
Active
Viewed 977 times
1 Answers
2
From the Java-Doc of the setEchoChar()
method:
Setting a value of 0 indicates that you wish to see the text as it is typed, similar to the behavior of a standard JTextField.
So just use:
second.setEchoChar((char)0);
to set and to reset:
second.setEchoChar('\u2022');
The default EchoChar
is determined by the Look & Feel. To be always in harmony with the theme it's the best to save the default EchoChar
before changing it the first time:
char originalEchoChar = second.getEchoChar();

Dennis Kriechel
- 3,719
- 14
- 40
- 62
-
How would i set it back to the dots though? – Bill Nye Dec 11 '15 at 11:36
-
just use the old value again (e.g. '*') – Dennis Kriechel Dec 11 '15 at 11:37
-
in what way, i tried this second.setEchoChar((char)*); and the '*' is highlighted in red. – Bill Nye Dec 11 '15 at 11:39
-
you wont need the `(char)` here instead: `second.setEchoChar('*');` – Dennis Kriechel Dec 11 '15 at 11:40
-
The JTextField is using a bullet point, would there be any way to get that? – Bill Nye Dec 11 '15 at 11:43
-
@BillNye I took me a while to get it, but it's rly simple, just use the unicode bullet icon, check my edit. The default Echo Char is determent by the look and feel and is by default the bullet. To be sure to be always in collaboration with the theme you can call `getEchoChar` before changing the char the first time and store this value for the reset – Dennis Kriechel Dec 11 '15 at 11:50