I tried to create a floating dialog box which contains a loader gif image and some text. I have got the following class:
public class InfoDialog extends JDialog {
public InfoDialog() {
setSize(200, 50);
setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
setUndecorated(true);
setLocationRelativeTo(null);
URL url = InfoDialog.class.getClassLoader().getResource("loader.gif");
ImageIcon loading = new ImageIcon(url);
getContentPane().add(new JLabel("Logging in ... ", loading, JLabel.CENTER));
}
}
However, when I call:
InfoDialog infoDialog = new InfoDialog()
infoDialog.setVisible(true);
An empty dialog is shown. The ImageIcon and the Label is not shown in the dialog box.
What did I do wrong in this code?
Many thanks.