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 透明?
基础教程推荐
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 大摇大摆的枚举 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
