Dean Hiller
Dean Hiller

Reputation: 20182

how to modify JTextField to mask characters and not use JPasswordField because of this

We have an application that can mask numbers on nearly any application, win32, browser, terminals, even SWT that eclipse uses, but Swing is another issue.

For this question, assume I am part of the JVM and that I just inserted my jar on the classpath and I am the main program that calls someone else's main program so I have access to everything inside the JVM that I need BUT I did not write the original application that used these JTextFields!!!!

If an application has a JTextField, how can I modify it so it still stores the digits I set into it as well as mask it so it displays like the JPasswordField BUT still has all the listeners the original application writer has written. Also, when they click the Ok button or Next button or Submit button, my newly masked field should be applied just like it was the old JTextField and nothing changed.

thanks, Dean

Upvotes: 1

Views: 2198

Answers (2)

Dean Hiller
Dean Hiller

Reputation: 20182

Unfortunately in my case the other answer doesn't work since I don't have access to change the application as it's not mine...I can however bytecode change the application though raw jdk classes are tricky. I can get my jar on the classpath and I can get my jar to run before the program starts up. I could do this for win32 applications but it is very difficult for java applications unfortunately.

Upvotes: 0

Radu Murzea
Radu Murzea

Reputation: 10900

If you want to do something like this, it means you have permission and possiblity to change the application. In this case, just replace JTextField with JPasswordField. It will hide the characters, which is exactly what you're after.

Also, you don't have to worry about listeners or method calls on the text-fields: they will still work because JPasswordField is a subclass of JTextField.

Upvotes: 3

Related Questions