Have a problem with GUI. How to add text in jTextFiled that will disappear when I click on this field? Have no idea how to realize this. jTextField has only one field for this property. Thank you!
Asked
Active
Viewed 2,156 times
0
-
You could also have a look at SwingLabs, SwingX library which has `PromptSupport` (and `BuddySupport`), for [example](http://stackoverflow.com/questions/29338788/how-to-set-a-default-text-to-jformattedtextfield/29338892#29338892), [example](http://stackoverflow.com/questions/22807407/force-jtextfield-to-string-value-while-documentfilter-only-allows-digits/22827937#22827937), [example](http://stackoverflow.com/questions/20578568/java-swing-listen-an-action-in-a-text-field-of-a-form/20578601#20578601) – MadProgrammer Mar 11 '16 at 21:20
-
Please follow http://stackoverflow.com/help/how-to-ask about how to ask proper questions. SO should not be used to ask for libraries or software... – Stephen Reindl Mar 11 '16 at 21:55
1 Answers
1
You can use the Text Prompt class which adds this functionality to any text field.
You have a property to control when the prompt is displayed.
The class basically adds a child (JLabel) to the text field which is painted when the text field doesn't have any text.

camickr
- 321,443
- 19
- 166
- 288