给 JTextArea 添加水印 [英] Adding a watermark to a JTextArea

查看:64
本文介绍了给 JTextArea 添加水印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它们是一种将 水印 添加到 JTextArea?

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

推荐答案

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

I suspect that you'd need to subclass JTextArea and override the paintComponent() method, drawing your background image first and calling super.paintComponent() to render the text:

public void paintComponent (Graphics g) {
    g.drawImage(watermark, 0, 0, this);
    super.paintComponent(g);
}

正如 camickr,一个 JTextArea 是不透明的,所以你的子类需要通过调用 setOpaque(false) 来改变它.

edit: as pointed out by camickr, a JTextArea is opaque, so your subclass will need to change this by calling setOpaque(false).

这篇关于给 JTextArea 添加水印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆