Dementor Dementor - 1 month ago 17
Java Question

Java SplashScreen transparent image

I have an application that takes 6 seconds to start, and I want to add a splash screen.
I have this code:

public class SplashScreen extends JWindow {
private static final long serialVersionUID = 1L;

Image bi;
ImageIcon ii;

boolean loaded = false;

public SplashScreen(String path) {
try {
bi = Toolkit.getDefaultToolkit().getImage(path);
ii = new ImageIcon(bi);
setSize(ii.getIconWidth(), ii.getIconHeight());
setLocationRelativeTo(null);
loaded = true;
} catch (Exception exception) {
exception.printStackTrace();
}
}

public void showSplashScreen(boolean flag) {
if (!loaded) {
System.err.println("Splash screen image isn't loaded.");
return;
}
setVisible(flag);
}

public void dispose() {
dispose();
}

public void paint(Graphics g) {
g.drawImage(bi, 0, 0, null);
}
}


The picture looks fine, but I want it to look transparent, and I can not get it.

Answer

I solved my problem, i added this line:

setBackground(new Color(0, 255, 0, 0));