Example text in JTextField

后端 未结 7 2128
独厮守ぢ
独厮守ぢ 2021-01-18 05:15

I am looking for a way to put example text into a swing JTextField and have it grayed out. The example text should then disappear as soon as any thing is entered into that t

7条回答
  •  日久生厌
    2021-01-18 05:34

    How about initialize the text field with default text and give it a focus listener such that when focus is gained, if the text .equals the default text, call selectAll() on the JTextField.

提交回复
热议问题