1
votes

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?

1
Where is located the .gif relative to the root folder of your project ? - flawyte
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 shows how to use an animated BG in a frame. Maybe it will help. 5) For better help sooner, post an SSCCE that hot-links to an image like the source in point (4). - Andrew Thompson

1 Answers

1
votes

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