Search code examples
javaswingjdialoganimated-gif

How to set GIF background for JDialog?


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?


Solution

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