Java:透明文本区域 +绘制背景

发布于 2024-12-24 18:57:42 字数 87 浏览 4 评论 0原文

我的问题很简单。 JTextArea 可以设置为透明,但不能完全不可见吗?另外,如果可能的话,如何在其后面绘制图像(先绘制图像,然后在其上方绘制透明文本区域)?

My question here is fairly simple. Can JTextArea's be set to transparent, but not completely invisible? Also, if it's possible, how can I draw an image behind it (draw the image first, and then draw the transparent text area overtop of it)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寻梦旅人 2024-12-31 18:57:42

1) 重写 JTextArea 的 PaintComponent() 方法,如下所示:

g.drawImage(...);
super.paintComponent(g);

2) 创建文本区域时,您需要为其提供透明背景:

setBackground( new Color(r, g, b, alpha) );

1) Override the paintComponent() method of the JTextArea something like:

g.drawImage(...);
super.paintComponent(g);

2) When you create the text area you will need to give it a transparent background:

setBackground( new Color(r, g, b, alpha) );
暗藏城府 2024-12-31 18:57:42

您也可以这样做:

jScrollPane.setOpaque(false);
jScrollPane.getViewport().setOpaque(false);
jScrollPane.setBorder(null);
jScrollPane.setViewportBorder(null);

jTextArea.setBorder(null);
jTextArea.setBackground(new Color(0, 0, 0, 0));

jscrollpane 是 jtextarea 的直接父组件。

You could also do this:

jScrollPane.setOpaque(false);
jScrollPane.getViewport().setOpaque(false);
jScrollPane.setBorder(null);
jScrollPane.setViewportBorder(null);

jTextArea.setBorder(null);
jTextArea.setBackground(new Color(0, 0, 0, 0));

jscrollpane is the immediate parent component of the jtextarea.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文