1

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 :

Overlay blurring background

Soheil
  • 1,676
  • 7
  • 34
  • 65
  • @MadProgrammer I simply mean what you see in that image! (a manner that the contents of the frame are not in details....) – Soheil Feb 12 '13 at 20:06
  • Uhm I dont get how this will be incorporated to a OS GUI. Because technically the top dialog would be sized to fit its contents and the frame behind will remain its current size. Using JFrame and JDialog would give this effect by default with modality (of course taking it that the JFrame is larger than the JDialog) – David Kroukamp Feb 12 '13 at 20:07
  • @DavidKroukamp `Using JFrame and JDialog would give this effect by default with modality` excuse me ?!!!! – Soheil Feb 12 '13 at 20:09
  • Well except the blurring... is that what you want? – David Kroukamp Feb 12 '13 at 20:11
  • @DavidKroukamp if `blurring` means what you see in the image, so yes ! – Soheil Feb 12 '13 at 20:13
  • See also [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/a/9554657/418556) – Andrew Thompson Feb 13 '13 at 10:24

3 Answers3

6

Now how to make the previous frame blurred?

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319
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.

Gilbert Le Blanc
  • 50,182
  • 6
  • 67
  • 111
1

There is the setOpacity(float opacity) method that is available in JFrame (inherited from Frame actually).

Dan D.
  • 32,246
  • 5
  • 63
  • 79
  • Wait, `Frame` is from `java.awt`, isn't it? I thought the `java.awt` package wasn't available on Android? – 11684 Feb 12 '13 at 20:06
  • 2
    @11684 I think the screenshot is just an example of the desired effect, it doesn't indicate that the OP is programming in Android. – millimoose Feb 12 '13 at 20:07
  • Yes, that made me think already, but I thought there was a Android port of Swing maybe.. – 11684 Feb 12 '13 at 20:07
  • not related to what i want. look at the image another time, i don't want a transparent frame, i want a frame that its contents are not visible in details... – Soheil Feb 12 '13 at 20:07
  • @11684 JFrame is in Swing, the question is about Swing, the screenshot is just an example. – Dan D. Feb 12 '13 at 20:13