Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to black out a Swing component?

Tags:

java

swing

Hi have a requirement where on some condition I have to black out the swing component(Text Field) preserving its string value. ie the component should not show what string value it holds.

like image 256
GuruKulki Avatar asked Dec 06 '22 14:12

GuruKulki


1 Answers

There is JPasswordField, which is a text field that can be toggled to show ** (or some other echo character) instead of the actual content. That is probably the easiest way.

If that isn't good enough, you could pull the content and store it externally, blank or blot or whatever the field, and setEnabled(false) on it. When you enable the field again, put the content back. If it's necessary to use getText() in the meantime, you'll have to override that so you can substitute the stored content when appropriate.

like image 131
CodeClown42 Avatar answered Dec 15 '22 08:12

CodeClown42