I would like to develop a form with some text field.
example:
Name SecondName
the idea is that every text field have inside a text like:
Insert your name Insert your second name
when you click on the first text field to write your name, the text "Insert your name" have to be deleted... the same have to happen for the second text field (SecondName).
The effect have to be this:
I think that i just need an Action on the text field that have to wake up when the user press on the mouse on the text field, it's possible?
Thank you
Take a look at Text Prompt for a simple solution that allows you to control when the text is displayed/hidden as well as the font/color of the text.
It will work with regular text components. In its simplest form you only need one extra line of code:
Take a look at
PromptSupport
in SwingLabs SwingX LibraryFor Example
When the fields have focus, the "prompt" will be hidden, but you can control this, making it shown until the user types something or highlight when focus is gained.
I've also added an example of
BuddySupport
which is part of the same API, which allows you to "buddy" another component with a text component. Here I've done the classic "file browser" combination, but I do "search" style fields like this all the time...see this example