My problem is that when adding a .GIF to a JPanel, it shows this black square background for the .GIF.
Result when adding on JPanel:
It happens when I use this line:
p2.add(loadBar); // where p2 = new JPanel();
However, when I add the same .GIF on the JFrame, the black square is not there anymore. Like this:
jf.add(loadBar); // where jf = new JFrame();
Result when adding on JFrame:
Part of the class code:
String loadLink = "http://i.imgur.com/mHm6LYH.gif";
URL ajaxLoad = null;
try {
ajaxLoad = new URL(loadLink);
} catch (MalformedURLException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
}
ImageIcon loading = new ImageIcon(ajaxLoad);
JLabel loadBar = new JLabel(loading);
loadBar.setBounds(70, 60, 54, 55);
loadBar.setOpaque(false);
//jf.add(loadBar);
p2.add(loadBar);
Could someone please explain why it is happening like this? Thank you for your time and reading.
EDIT:
// Creates the Initialization Panel
p2 = new JPanel();
// Sets the background, black with 125 as alpha value
// This is less transparent
p2.setLayout(null);
p2.setBackground(new Color(0,0,0,150));
// Sets a border to the JPanel
p2.setBorder(new LineBorder(Color.WHITE));
// Sets some size to the panels
p2.setBounds(20, 20, 200, 150);
// Adds the loading gif
String loadLink = "http://i.imgur.com/mHm6LYH.gif";
URL ajaxLoad = null;
try {
ajaxLoad = new URL(loadLink);
} catch (MalformedURLException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
}
ImageIcon loading = new ImageIcon(ajaxLoad);
JLabel loadBar = new JLabel(loading);
loadBar.setBounds(70, 60, 54, 55);
loadBar.setOpaque(false);
p2.add(loadBar);
That is the JPanel which is shown in the first image without the JLabel. I can't really show the JFrame part in the code because it is spread all over the class. But I don't think the problem is with JFrame so it could be this JPanel :/