透明背景上的文物
我在 JFrame 中有一个具有半透明背景的 JLabel,但我在字母周围出现了一些伪影。
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.io.IOException;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Main {
public static void main(String[] args) {
JFrame frame = new JFrame();
JLabel label = new JLabel("Hello World!");
frame.setPreferredSize(new Dimension(200, 200));
frame.setUndecorated(true);
frame.setBackground(new Color(128, 128, 128, 128));
//label.setOpaque(false);
//label.setBackground(new Color(0, 0, 0, 0));
//((JPanel) frame.getContentPane()).setOpaque(false);
//((JPanel) frame.getContentPane()).setBackground(new Color(0, 0, 0, 0));
frame.add(label);
frame.pack();
frame.setVisible(true);
}
}
我已经尝试对这些组件应用不透明度,但没有运气。我希望所有组件都是完全不透明的,因此 JFrame 的 java7 每像素透明度似乎是唯一的解决方案。
I've got a JLabel in a JFrame with a semi-transparent background, but I'm getting some artifacts around the letters.
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.io.IOException;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Main {
public static void main(String[] args) {
JFrame frame = new JFrame();
JLabel label = new JLabel("Hello World!");
frame.setPreferredSize(new Dimension(200, 200));
frame.setUndecorated(true);
frame.setBackground(new Color(128, 128, 128, 128));
//label.setOpaque(false);
//label.setBackground(new Color(0, 0, 0, 0));
//((JPanel) frame.getContentPane()).setOpaque(false);
//((JPanel) frame.getContentPane()).setBackground(new Color(0, 0, 0, 0));
frame.add(label);
frame.pack();
frame.setVisible(true);
}
}
I already tried applying opacity to these components without luck. I'd like all Components to be fully opaque, so java7 per-pixel transparency for the JFrame seems to be the only solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能只使用具有透明度的颜色作为背景。请参阅透明背景了解说明和潜在的解决方案。
You can't just use Colors with transparency as a background. See Background With Transparency for an explanation and potential solution.
我无法重现您的问题,也许我的电池没电了,但是您的 GPU 没有问题吗???
我尝试了 @camickr 的建议,没有发生任何错误
和
基于教程 如何创建半透明和形状的窗口
I can't to reproduced your issue, maybe I'm out-off battery, but isn't there some issue with your GPU ???
I tried suggestion by @camickr, nothing wrong happened
and
based on code from tutorial How to Create Translucent and Shaped Windows