How to make JFrame transparent?(如何使 JFrame 透明?)
问题描述
如何让JFrame透明?我想让我的 JFrame 透明.当我的 JFrame 位于其顶部时,用户应该会看到背景.
How to make JFrame transparent? I want to make my JFrame transparent. User should see the background when my JFrame is on top of it.
推荐答案
如果您对使用受限 API 类没有任何异议,那么您可以使用 AWTUtilities 类和 setWindowOpacity() 该类的方法.这里 和 这里是关于如何使用它的教程?而这里是使用Java原生访问的版本.
If you do not have any objection in using restricted API classes then you can do this with AWTUtilities class and setWindowOpacity() method of that class. Here and here is a tutorial on how to use it? And here is the version using Java native access.
代码示例
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
javax.swing.JFrame fr = new NewJFrame();
com.sun.awt.AWTUtilities.setWindowOpacity(fr, 0.7 f);
fr.setVisible(true);
}
});
}
这篇关于如何使 JFrame 透明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使 JFrame 透明?
基础教程推荐
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 存储 20 位数字的数据类型 2022-01-01
