JTextField Placeholder Text
843807Mar 4 2010 — edited Mar 5 2010Lets say I have a form that asks for someone's address. Instead of having labels to the left of each field, I want to have gray placeholder text inside the textfield that would say "Street" or "Zip Code" etc. Once focus goes to the textfield, the placeholder text should go away. Placeholder text is not shown if there is any non-zero-length text already in the textfield.
If I say textField.getText() it should never return me the placeholder text.
I've tried multiple ways of doing it. The latest thing I tried was creating my own TextFieldUI which extends BasicTextFieldUI, but this didn't work.
Anyone know how to do this or has anyone done this with swing before?
Thanks!