Search code examples
javaswingjtextfield

How to Clear the textfield when any key is pressed?


I have a textfield in my application with some text already in it. I want to clear that text as soon as i press first key. I tried to use keyListener but it is deleting text every single type i press any key. So is there any way, with which, I can clear initial text on only first keypress?


Solution

  • I think that you looking for Text Prompt.