简体   繁体   English

如何在Java中使JFrame模糊?

[英]How to make a JFrame blurred in java?

In my java program, when the user clicks on a button in the main JFrame another JFrame becomes visible on top of the main frame. 在我的Java程序中,当用户单击主JFrame的按钮时,另一个JFrame在主框架的顶部变为可见。 Now how to make the previous frame blurred? 现在如何使前一帧模糊? Exactly like the background in the image : 就像图片中的背景一样:

叠加模糊的背景

Now how to make the previous frame blurred? 现在如何使前一帧模糊?

I'm assuming that you are coding using Java Swing, and the picture is the effect you want. 我假设您正在使用Java Swing进行编码,而图片就是您想要的效果。

You would use a JDialog to create the top window, rather than a JFrame . 您将使用JDialog而不是JFrame创建顶部窗口。 A JDialog is designed to be modal. JDialog被设计为模态的。 In other words, lock the JFrame until the JDialog is closed. 换句话说,锁定JFrame直到关闭JDialog

The default behavior of a JDialog is to not blur or darken the underlying JFrame . JDialog的默认行为是不使基础JFrame模糊或变暗。 In order to darken the underlying JFrame , you're going to have to paint a black image on the glass pane of the JFrame . 为了使底层JFrame变暗,您将不得不在JFrame的玻璃窗格上绘制黑色图像。

This tutorial shows you how to manipulate the root panes of a JFrame . 教程向您展示如何操作JFrame的根窗格。

JFrame提供了setOpacity(float opacity)方法(实际上是从Frame继承)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM