1

How can I make light box effect in swing? I want to add JPanel on JFrame in layered pane and want to give lightbox effect in this. Is this possible in swing? Is there any swing component to do this?

Something like in following image:

Light box effect

Harry Joy
  • 58,650
  • 30
  • 162
  • 207

3 Answers3

4

This can be done using the graphics context's AlphaComposite. I'd start with 50% transparent black and adjust empirically. This handy utility may help.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • 1
    @trashgod: Thanks for support. I made it with combination of JLayeredPane and AlphaComposite. – Harry Joy Jul 08 '11 at 06:05
  • See also this [example](http://stackoverflow.com/questions/6822869/using-gridbaglayout-in-a-jlayeredpane/6823589#6823589). – trashgod Jul 26 '11 at 16:26
2

I want to add a panel on a frame which is already loaded with data

You should be able to use Layered Panes. You can add transparent panels to the top layer.

Or maybe you are talking about a Glass Pane.

camickr
  • 321,443
  • 19
  • 166
  • 288
  • currently I'm doing `myFrame.getLayeredPane().add(new MyPanel())`. But I'm not able to add a transparent layer [blackPanel in image]. – Harry Joy Jul 08 '11 at 05:24
  • Read the tutorial. You should add your own layered pane to the content pane. Post your SSCCE if you have problems. – camickr Jul 08 '11 at 05:27
  • Thanks for support. I made it with combination of JLayeredPane and AlphaComposite. – Harry Joy Jul 08 '11 at 06:05
1

JXLayer is the way to go. A good starting point for using it is this tutorial.

01es
  • 5,362
  • 1
  • 31
  • 40