1

The following code is for making JDialog:

private class InfiniteDialog extends JDialog {

    @Override
    public void paintComponents(Graphics g)
    {
        super.paintComponents(g);
        g.drawImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/images/menu_icons/loading.gif")), 0, 0, null);
    }   
}

And here is some code for executing:

    JDialog dialog=new InfiniteDialog();
    dialog.setSize(300, 300);
    dialog.setVisible(true);

But I can see the dialog without background. Please, tell me, how can I fix it?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
malcoauri
  • 11,904
  • 28
  • 82
  • 137
  • 1
    Where is located the .gif relative to the root folder of your project ? – Mickäel A. Nov 08 '12 at 14:28
  • 1
    [here are (could be) answers](http://stackoverflow.com/questions/tagged/java+swing+animated-gif) – mKorbel Nov 08 '12 at 14:28
  • 1) `public void paintComponents(Graphics g)` should be singular, e.g. `public void paintComponent(Graphics g)` 2) Do not try to load an image in the paint method! Nothing potentially long running whould be done there. 3) A `JDialog` is an `ImageObserver` so `null` should be `this`. 4) [This answer](http://stackoverflow.com/a/10836833/418556) shows how to use an animated BG in a frame. Maybe it will help. 5) For better help sooner, post an [SSCCE](http://sscce.org/) that hot-links to an image like the source in point (4). – Andrew Thompson Nov 09 '12 at 00:19

1 Answers1

1

First try to clean + refresh your project in your IDE. Then try to remove the "/" at the beginning of the path.

Mickäel A.
  • 9,012
  • 5
  • 54
  • 71