Search code examples
javaswingjtextfield

How to display a default message in JTextField java


I want to create a JTextField with a message inside as a deafult. But not as a proper text but as a comment about what to type inside the JTextField. So if i type jtf.getText() it returns null or empty because it is just a comment that was printed there. When you click on it then it disappears and you can write whatever you want on it. Is there any method to do such a thing?


Solution

  • I believe what you want is input hint in the text field, something like the image below:

    input hint

    Check xswingx library which can do this.