Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JTextField Placeholder Text

843807Mar 4 2010 — edited Mar 5 2010
Lets 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!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 2 2010
Added on Mar 4 2010
2 comments
11,942 views