Seguinte, estou criando uma tela Splach para minha aplicação java, e estou adicionando um png como fundo, porém, precisaria deixar o background transparente, para deixar apenas a imagem visível.
segue o código:
import com.sun.awt.AWTUtilities;
import java.awt.*;
import javax.swing.*;
public class SplashScreen extends JWindow
{
private int duration;
private ImageIcon fundoSplash;
public SplashScreen(int d)
{
duration = d;
}
public void showSplash()
{
JPanel content = (JPanel)getContentPane();
content.setBackground(new Color(0, 0, 0, 125));
// Configura a posição e o tamanho da janela
int width = 500;
int height = 250;
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
int x = (screen.width-width)/2;
int y = (screen.height-height)/2;
setBounds(x, y, width, height);
fundoSplash = new ImageIcon(getClass().getResource("/imagens/fundo2.png"));
JLabel label = new JLabel(fundoSplash);
content.add(label, BorderLayout.CENTER);
setVisible(true);
try
{
Thread.sleep(duration);
}
catch (Exception e)
{
}
setVisible(false);
}
public void showSplashAndExit()
{
showSplash();
System.exit(0);
}
public static void main(String[] args)
{
SplashScreen splash = new SplashScreen(10000);
splash.showSplashAndExit();
}
}