0

I have a loading sign gif - animated and transparent background. How can I use it in Java - show it's animation and make its background transparent?

I use this code to load it as splashscreen

I'm creating gif transparent animation with ajaxload

onkar
  • 4,427
  • 10
  • 52
  • 89
SharonBL
  • 1,735
  • 5
  • 20
  • 28
  • What have you done till now, any [SSCCE](http://sscce.org) – Branislav Lazic Aug 31 '12 at 21:53
  • [See this question](http://stackoverflow.com/questions/8783535/java-swing-loading-animation) – Brian Aug 31 '12 at 21:54
  • I didn't manage to do anything, so i deleted my code. In general - I tried to load if on a Jlabel - animation was shown, but the background wasn't transparent. When using opacity on the jpanel - everything becomes transparent. So - no luck :-( – SharonBL Aug 31 '12 at 22:02
  • I think this will solve your problems http://java.sun.com/developer/technicalArticles/GUI/translucent_shaped_windows/ – fonZ Aug 31 '12 at 22:16
  • I updated my question. Jonathan.cruz - I tried this and didn't helped me. probably it's the rendering of the gif or something. – SharonBL Aug 31 '12 at 22:25

2 Answers2

1

You mean, perhaps something like...

Super

The easiest way is to start with a ImageIcon and a JLabel

ImageIcon animatedGif = new ImageIcon(...); // Path/URL to your gif
JLabel splashLabel = new JLabel(animatedGif);

// Add to your splash screen...

Once you have the basic set up, you will probably want to undecorated the frame (or just use a JWindow)

myJFrame.setUndecorated(true);

Oh, of course, if you want something really over the top, you use a transparent window...

Over the top

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • I tried you solution (JFrame and JWindow) and again - i see the animated gif as expected, BUT - it's not transparent - it as a light grey non-transparent background :-( Any other ideas? – SharonBL Sep 01 '12 at 10:16
  • There's a few little tricks, first, make sure the actual container is transparent (this includes the content pane of the window). Have a read through [How to Create Translucent and Shaped Windows](http://java.sun.com/developer/technicalArticles/GUI/translucent_shaped_windows/) – MadProgrammer Sep 01 '12 at 10:40
  • AWTUtilities.setWindowOpaque(myJFrame, false) did the trick! thank you very much!! – SharonBL Sep 01 '12 at 12:10
0

Thanks to MadProgramer Here is a working code:

    ImageIcon icon = new ImageIcon("images/ajax-loader.gif");
    JLabel label=new JLabel(icon);
    JWindow myJFrame=new JWindow();
    myJFrame.setLayout(new BorderLayout());
    myJFrame.add(label,BorderLayout.CENTER);
    myJFrame.setLocationRelativeTo(null);
    myJFrame.setOpacity(0.5f);
    myJFrame.setAlwaysOnTop(true);
    label.setOpaque(false);
    AWTUtilities.setWindowOpaque(myJFrame, false);
    myJFrame.pack();
    myJFrame.setVisible(true);
Community
  • 1
  • 1
SharonBL
  • 1,735
  • 5
  • 20
  • 28