Janela JFrame Recortado ou Transparente

2 respostas
java
J
Bom dia!

Estava usando o com.sun.awt.AWTUtilities.setWindowShape(); para Recortar o JFrame.

e

Estava usando o com.sun.awt.AWTUtilities.setWindowOpacity(); para deixá-lo Transparente o JFrame.

Logo vi que esse código era ultrapassado.

Queria saber de um código atual para recortar o JFrame.

Alguém tem alguma ideia?

.

.

.

JFrame Recortado!

.

.

.

import java.awt.*;

import java.awt.geom.Ellipse2D;

import javax.swing.*;

public class ShapedWindow extends JFrame {

public ShapedWindow() {

super(Test oval-shaped window);

this.setLayout(new FlowLayout());

this.add(new JButton(test));

this.add(new JCheckBox(test));

this.add(new JRadioButton(test));

this.add(new JProgressBar(0, 100));
this.setSize(new Dimension(400, 300));
	this.setLocationRelativeTo(null);
	this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public static void main(String[] args) {
	JFrame.setDefaultLookAndFeelDecorated(true);
	SwingUtilities.invokeLater(new Runnable() {
		@Override
		public void run() {
			Window w = new ShapedWindow();
			w.setVisible(true);
			com.sun.awt.AWTUtilities
					.setWindowShape(w, new Ellipse2D.Double(0, 0, w
							.getWidth(), w.getHeight()));
		}
	});
}
}

.

.

.

JFrame Transparente!

.

.

.

import java.awt.*;

import javax.swing.*;

public class TranslucentWindow extends JFrame {

public TranslucentWindow() {

super(Test translucent window);

this.setLayout(new FlowLayout());

this.add(new JButton(test));

this.add(new JCheckBox(test));

this.add(new JRadioButton(test));

this.add(new JProgressBar(0, 100));
this.setSize(new Dimension(400, 300));
	this.setLocationRelativeTo(null);
	this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public static void main(String[] args) {
	JFrame.setDefaultLookAndFeelDecorated(true);
	SwingUtilities.invokeLater(new Runnable() {
		@Override
		public void run() {
			Window w = new TranslucentWindow();
			w.setVisible(true);
			com.sun.awt.AWTUtilities.setWindowOpacity(w, 0.5f);
		}
	});
}

}

2 Respostas

rodriguesabner
setShape(new RoundRectangle2D.Double(
                x, //posição horizontal
                y, //posição vertical
                width, //largura
                height, //altura
                corner1, //borda redonda 1 
                corner2)); //borda redonda 2

 setOpacity(0.8f); //float
J

Tem como fazer animação com o JFrame? Como?

Criado 29 de novembro de 2019
Ultima resposta 29 de nov. de 2019
Respostas 2
Participantes 2