1

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

Dean Hiller
  • 19,235
  • 25
  • 129
  • 212
  • I think I understand **what** you are trying to achieve, but what I'm really curious about is **why?** What is the use-case for this (rather unusual) requirement to blot out text in apps. that are not normally used for 'security' purposes? – Andrew Thompson Jun 13 '12 at 22:51
  • 1
    I really do not understand much. What? – Paul Vargas Jun 13 '12 at 22:53
  • use case is social security numbers, etc. that are typed in by agents and we instead key them in for agents but don't want it to be visible. – Dean Hiller Jun 20 '12 at 18:06

2 Answers2

3

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.

Radu Murzea
  • 10,724
  • 10
  • 47
  • 69
  • let's say I use reflection after the app started up. The app will have added listeners to JTextField and I remove that JTextField(that had listeners on it) and put in my JPasswordField(which the app won't know about and won't add listeners to). That doesn't feel like it will work???? What am I missing? – Dean Hiller Jun 16 '12 at 00:31
0

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.

Dean Hiller
  • 19,235
  • 25
  • 129
  • 212