1

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.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
mlomb
  • 172
  • 4
  • 18
  • [See The following link to make your image transparent][1] [1]: http://stackoverflow.com/questions/665406/how-to-make-a-color-transparent-in-a-bufferedimage-and-save-as-png – Muhammad Dec 21 '13 at 16:06
  • @Muhammad My image is Png transparent... Thats for create a image PNG with transparency – mlomb Dec 21 '13 at 16:13

2 Answers2

4

I solved my problem, i added this line:

setBackground(new Color(0, 255, 0, 0));
mlomb
  • 172
  • 4
  • 18
0

you can set The opacity of your JWindow that will make it transparent

setUndecorated(true); setOpacity(0.5f);

I am using JFrame and it will remove the titlebar too,

it worked for me

Muhammad
  • 6,725
  • 5
  • 47
  • 54