I don’t know if I got the right name for it, but I’m looking to see if there is a specific way to implement a text field so that while it doesn’t have focus and is empty, a faint gray string of text is displayed in the field. When the field is clicked, the text should go away, exactly like how the Search bar like that of StackOverflow works. I know that I can change use setForeground() and focus listeners to accomplish this, but I was just wondering if anyone knew of some Java implementation that could handle this for me.
I don’t know if I got the right name for it, but I’m looking
Share
For what it’s worth, I found it interesting to actually implement it, so I thought to share it with you (I am not looking for votes).
It’s really non-invasive since all you have to do is call
new GhostText(textField, "Please enter some text here...");. The rest of the code is only to make it run.