I'd like to display a GlassPane
with a sort of blur effect. Broadly speaking, something like this:
I tried using as GlassPane
a JPanel
with transparent background. Here's the code of my custom panel.
JPanel glassPane = new JPanel(){
@Override
public void paint(java.awt.Graphics g) {
Graphics2D g2 = (Graphics2D)g.create();
g2.setRenderingHint(java.awt.RenderingHints.KEY_ANTIALIASING,java.awt.RenderingHints.VALUE_ANTIALIAS_ON);
g2.setComposite(java.awt.AlphaComposite.SrcOver.derive(0.5f));
g2.setPaint(myColor);
g2.fillRect(0,0,this.getWidth(),this.getHeight());
g2.dispose();
};
}
The problem is that when I load the GlassPane
I have a sort of overlapping issue. I.e. it seems that all the elements of the below UI (the ones displayed in the panel below the just loaded glass pane) are randomly mirrored on the GlassPane
. This happens not only in GlassPane
, but every time I try to use trnsparent colors with Graphics2d
.
This is what i get:
Any idea on how to create a transparent GlassPane
avoiding this annoting issue?