As you can see in the title i dont know how to make a java text field with text in the background that disappears when you click on it. So theres a textfield that says "username" and when u click on it the username disapears and you can type in your password. Is it possible to do this without a new class?
Asked
Active
Viewed 410 times
0
-
1Which kind of textfield are you using (AWT, Swing, JavaFX, foofields...)? – Arnaud Nov 27 '18 at 09:34
-
jtextfield from javax.swing – Terry McGovern Nov 27 '18 at 09:36
-
1Possible duplicate of [java swing JTextField set PlaceHolder](https://stackoverflow.com/questions/16213836/java-swing-jtextfield-set-placeholder) – Arnaud Nov 27 '18 at 09:36
-
can you do that without a new class? – Terry McGovern Nov 27 '18 at 09:38
-
`JTextField` doesn't have this feature, but if you don't want to subclass it, you may use `FocusListener` like the third answer in the above link. – Arnaud Nov 27 '18 at 10:02
1 Answers
0
my suggestion is to use swingx library and use JXTextField. so you can set the text using setPrompt method.

hunter
- 3,963
- 1
- 16
- 19