• Post Reply Bookmark Topic Watch Topic
  • New Topic

Display watermark image in JTextField  RSS feed

 
Jared Cope
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I was wondering if it was possible to display a background image in a text field. The user should still be able to type text into the field on top of the image.

Setting the background colour is an option, but I really want to display an image instead.

What I need is a method like:



Cheers, Jared.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this:

 
Jared Cope
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the code. It almost worked for me, except that the user text always appears under the image. I couldn't figure out how to keep the text on top of the image.

What I went for instead was to create a JPanel with the desired background image on it, then added the JTextField to the panel and set the text field opaque value to false. The image then shows up underneath the text field and the text appears on top of the image as it is typed.

Cheers, Jared.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Odd that your text goes under the image. Isn't it the other way in my example? Oh well...
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!