gpt4 book ai didi

java - 如何让jTextArea背景透明

转载 作者:搜寻专家 更新时间:2023-11-01 03:03:29 26 4
gpt4 key购买 nike

我想做一个透明背景的jTextArea。我尝试设置背景(新颜色(0,0,0,0));jTextField 正在工作,jTextArea 没有工作。

喜欢这段代码。

// Not working.. Just remains gray.
jScrollPane1.setOpaque(false);
jScrollPane1.setBackground(new Color(0,0,0,0));
jTextArea1.setOpaque(false);
jTextArea1.setBackground(new Color(0,0,0,0));

// Working.. As it wants to be transparent.
jTextField1.setOpaque(false);
jTextField1.setBackground(new Color(0,0,0,0));

enter image description here

如何让jTextArea透明背景?

感谢和问候。

最佳答案

JScrollPane 是一个组合组件,它控制/包含一个 JViewport,它是进行绘图的组件。参见 API:

A common operation to want to do is to set the background color that will be used if the main viewport view is smaller than the viewport, or is not opaque. This can be accomplished by setting the background color of the viewport, via scrollPane.getViewport().setBackground(). The reason for setting the color of the viewport and not the scrollpane is that by default JViewport is opaque which, among other things, means it will completely fill in its background using its background color. Therefore when JScrollPane draws its background the viewport will usually draw over it.

因此,您还应该更改 JViewport 的不透明和颜色属性。您可以使用 jScrollPane1.getViewport() 访问它。

关于java - 如何让jTextArea背景透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30435186/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com