nin*_*ded 7

我怀疑你需要子类化JTextArea并覆盖paintComponent()方法,首先绘制背景图像并调用super.paintComponent()渲染文本:

public void paintComponent (Graphics g) {
    g.drawImage(watermark, 0, 0, this);
    super.paintComponent(g);
}
Run Code Online (Sandbox Code Playgroud)

编辑:正如camickr所指出的,a JTextArea是不透明的,所以你的子类需要通过调用来改变它setOpaque(false).

  • 您可能还想使用alpha通道来构建您的图像,其中包含将由super()绘制的内容 (3认同)