I would like to add a hint value to my javax.swing.JTextField
. It should look like Firefox rendering of <input type="text" title="bla">
. This creates an edit field with the text 'bla' in the background. If the textbox has focus the title-text disappears and just reappears if the user leaves the editbox without text.
Is there a (free) swing component that does something like this?
Here is a simple way that looks good in any L&F:
Take a look at this one: http://code.google.com/p/xswingx/
It is not very difficult to implement it by yourself, btw. A couple of listeners and custom renderer and voila.
Have look at WebLookAndFeel at https://github.com/mgarin/weblaf/
For any Swing component (that is, anything that extends JComponent), you can call the setToolTipText(String) method.
For more information, reference the following links:
You could create your own:
If you're still on Java 1.5, replace the
this.getText().isEmpty()
withthis.getText().length() == 0
.If you still look for a solution, here's one that combined other answers (Bart Kiers and culmat) for your reference: