views:

230

answers:

3

Is they a way of adding a watermark to a JTextArea?

+6  A: 
ninesided
You may also want to use alpha channel to compose your image with what will be painted by super()
Dmitry
Most watermarks are drawn OVER the content. If you want to do this, call super.paintComponent(g) first, and then draw your semitransparent watermark image (or text) over it. You can either chose to have a transparent image, or work with alpha composites to get the transparency effect.Also you may want to tile your watermark instead of just painting it on the upper left corner. I'd suggest you make a reusable Watermark container that paints the watermark over its content, so you are free to embed the JTextArea (watermarks scroll with the text) or JScrolledPane (watermark stays, text scrolls)
Peter Walser
+1  A: 

I doubt the suggestion given above will work. A JTextArea is opaque, so the text will paint over top of the image. So at the very least you will need to make the text area non-opague and you will then need to play with the background colors of the viewport and/or scrollpane.

If you want a reusable solution try creating an ImageBorder. The order of painting is:

a) paintComponent

b) paintBorder

c) paintChildren

So if you add the border to the text area it will paint on top of the text in a fixed location.

Or if you add the border to the viewport it will paint below the text is a floating location.

camickr
you can just setOpaque(false) and that solves that little problem.
ninesided
A: 

You may also consider using JXLayer which can create quite complex visual effects

Dmitry