FileDocCategorySizeDatePackage
WatermarkTextField.javaAPI DocExample1163Mon Jan 09 11:01:58 GMT 2006None

WatermarkTextField

public class WatermarkTextField extends JTextField

Fields Summary
BufferedImage
img
TexturePaint
texture
Constructors Summary
public WatermarkTextField(File file)

        super();
        img = ImageIO.read(file);
        Rectangle rect = new Rectangle(0,0,
                img.getWidth(null),img.getHeight(null));
        texture = new TexturePaint(img, rect);
        setOpaque(false);
    
Methods Summary
public static voidmain(java.lang.String[] args)

        JFrame frame = new JFrame("Watermark JTextField Hack");
        
        JTextField textfield = new WatermarkTextField(new File("red.png"));
        textfield.setText("A Text Field");
        frame.getContentPane().add(textfield);
        frame.pack();
        frame.show();
    
public voidpaintComponent(java.awt.Graphics g)

        Graphics2D g2 = (Graphics2D)g;
        g2.setPaint(texture);
        g.fillRect(0,0,getWidth(),getHeight());
        super.paintComponent(g);