[RESOLVIDO] JFrame Desfocado

Fala pessoal, tô tentando deixar meu JFrame desfocado assim que um JDialog abrir, agora estou testando clicando num botão e tentando desfocar.

O problema é que ele só desfoca no initComponents, em tempo de execução ele não muda. Quando eu clico no botão ele trava o sistema, mesmo usando uma Thread. Não apresenta erro nenhum…

Exemplo de como está ficando:

Este é o JFrame normal:

image

Desfocado:

image

Classe pra desfocar:

class BlurLayerUI extends LayerUI<JComponent> {

        private BufferedImage mOffscreenImage;
        private final BufferedImageOp mOperation;

        public BlurLayerUI() {
            float ninth = 1.0f / 9.0f;
            float[] blurKernel = {
                ninth, ninth, ninth,
                ninth, ninth, ninth,
                ninth, ninth, ninth
            };
            mOperation = new ConvolveOp(
                    new Kernel(3, 3, blurKernel),
                    ConvolveOp.EDGE_NO_OP, null);
        }

        @Override
        public void paint(Graphics g, JComponent c) {
            int w = c.getWidth();
            int h = c.getHeight();

            if (w == 0 || h == 0) {
                return;
            }

            //pega o tamanho o jframe
            if (mOffscreenImage == null
                    || mOffscreenImage.getWidth() != w
                    || mOffscreenImage.getHeight() != h) {
                mOffscreenImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
            }

            Graphics2D ig2 = mOffscreenImage.createGraphics();
            ig2.setClip(g.getClip());
            super.paint(ig2, c);
            ig2.dispose();

            Graphics2D g2 = (Graphics2D) g;
            g2.drawImage(mOffscreenImage, mOperation, 0, 0);
        }
    }

Método pra desfocar:

public void add_blur() {
    new Thread() {
        @Override
        public void run() {
            LayerUI<JComponent> layerUI = new BlurLayerUI();
            JLayer<JComponent> jlayer = new JLayer<>(jPanel1, layerUI);

            add(jlayer, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, 390));
            //Se eu uso o repaint, a tela fica cinza
        }
    }.start();
}

Consegui. Basta adicionar essa linha no final do código:

SwingUtilities.updateComponentTreeUI(this);

Ficando assim:

public void add(){
    LayerUI<JComponent> layerUI = new BlurLayerUI();
    JLayer<JComponent> jlayer = new JLayer<JComponent>(jPanel1, layerUI);

    add(jlayer);
    SwingUtilities.updateComponentTreeUI(this);
}

Classe:

 class BlurLayerUI extends LayerUI<JComponent> {

        private BufferedImage mOffscreenImage;
        private BufferedImageOp mOperation;

        public BlurLayerUI() {
            float ninth = 1.0f / 9.0f;
            float[] blurKernel = {
                ninth, ninth, ninth,
                ninth, ninth, ninth,
                ninth, ninth, ninth
            };
            mOperation = new ConvolveOp(
                    new Kernel(3, 3, blurKernel),
                    ConvolveOp.EDGE_NO_OP, null);
        }

        @Override
        public void paint(Graphics g, JComponent c) {
            int w = c.getWidth();
            int h = c.getHeight();

            if (w == 0 || h == 0) {
                return;
            }

            // Only create the offscreen image if the one we have
            // is the wrong size.
            if (mOffscreenImage == null
                    || mOffscreenImage.getWidth() != w
                    || mOffscreenImage.getHeight() != h) {
                mOffscreenImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
            }

            Graphics2D ig2 = mOffscreenImage.createGraphics();
            ig2.setClip(g.getClip());
            super.paint(ig2, c);
            ig2.dispose();

            Graphics2D g2 = (Graphics2D) g;
            g2.drawImage(mOffscreenImage, mOperation, 0, 0);
        }
    }

Normal:

image

Desfocado:

image