问题
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. Now how to make the previous frame blurred?
Exactly like the background in the image :
回答1:
Now how to make the previous frame blurred?
have look at JLayer(Java7) based on JXLayer(Java6),
similair effect is possible with GlassPane, or with JViewport (not proper of ways, but good Swing GUI contains
JScrollPane
as 1st.JComponent
inJFrame
/JDialog
/JWindow
)
回答2:
I'm assuming that you are coding using Java Swing, and the picture is the effect you want.
You would use a JDialog
to create the top window, rather than a JFrame
. A JDialog
is designed to be modal. In other words, lock the JFrame
until the JDialog
is closed.
The default behavior of a JDialog
is to not blur or darken the underlying 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
.
This tutorial shows you how to manipulate the root panes of a JFrame
.
回答3:
There is the setOpacity(float opacity)
method that is available in JFrame
(inherited from Frame
actually).
来源:https://stackoverflow.com/questions/14840763/how-to-make-a-jframe-blurred-in-java