Gif not appearing in JLabel











up vote
2
down vote

favorite












I'm currently developing a programme which utilises gifs to indicate loading on the programme. However, I can not get the gif to appear on the JLabel after trying several ideas. I have tested many things, including the following.




  • Tried loading a png file instead of gif, this works, indicating no issue with the JLabel.

  • Tried loading the gif into a JLabel in a completely separate programme, this also works, indicating no issue with the gif.

  • Tried loading it in through URL AND through local resource, neither works.


The following snippet of code contains the main part of the declaration of the code. Any help is appreciated.



try {
URL URL = new URL("https://i.imgur.com/sMD9yUD.gif");
Icon Gif = new ImageIcon(URL);
tempLoad1.setIcon(Gif);
} catch (MalformedURLException e) {
e.printStackTrace();
}

tempLoad1.setHorizontalAlignment(SwingConstants.CENTER);
tempLoad1.setFont(new Font("Lato", Font.BOLD, 24));
tempLoad1.setBounds(63, 111, 452, 71);
contentPane.add(tempLoad1);


Note that tempLoad1 is declared at the start of the programme. I have also proved that this is not an issue.



Thanks in advance










share|improve this question
























  • 1) For better help sooner, post a Minimal, Complete, and Verifiable example or Short, Self Contained, Correct Example. 2) Java GUIs have to work on different OS', screen size, screen resolution etc. using different PLAFs in different locales. As such, they are not conducive to pixel perfect layout. Instead use layout managers, or combinations of them along with layout padding and borders for white space.
    – Andrew Thompson
    Nov 15 at 0:41










  • Q: What version of Java are you running? Q: What OS are you running it on?
    – paulsm4
    Nov 15 at 0:42










  • BTW - that code works just fine in an MCVE here. And it does that despite setting the bounds and the font (which is not used in any useful way). Post your own MCVE as an edit so we can see where it went wrong. (Voting to close.)
    – Andrew Thompson
    Nov 15 at 0:46










  • I'm not sure we actually need an MCVE: the problem is clear, and your code looks fine. I suspect it's just a "bad" .gif. SUGGESTION: get one of your .png files that "works", export it as a .gif, and see if the exported .gif displays. ALSO: I am curious about your Java version and your OS (on the off chance it might be relevant).
    – paulsm4
    Nov 15 at 0:50












  • "I'm not sure we actually need an MCVE:" Is that the royal 'we' @paulsm4? If not, don't speak for me. I'm certain the OP will not be getting my further attention until there is an MCVE in evidence.
    – Andrew Thompson
    Nov 15 at 1:00















up vote
2
down vote

favorite












I'm currently developing a programme which utilises gifs to indicate loading on the programme. However, I can not get the gif to appear on the JLabel after trying several ideas. I have tested many things, including the following.




  • Tried loading a png file instead of gif, this works, indicating no issue with the JLabel.

  • Tried loading the gif into a JLabel in a completely separate programme, this also works, indicating no issue with the gif.

  • Tried loading it in through URL AND through local resource, neither works.


The following snippet of code contains the main part of the declaration of the code. Any help is appreciated.



try {
URL URL = new URL("https://i.imgur.com/sMD9yUD.gif");
Icon Gif = new ImageIcon(URL);
tempLoad1.setIcon(Gif);
} catch (MalformedURLException e) {
e.printStackTrace();
}

tempLoad1.setHorizontalAlignment(SwingConstants.CENTER);
tempLoad1.setFont(new Font("Lato", Font.BOLD, 24));
tempLoad1.setBounds(63, 111, 452, 71);
contentPane.add(tempLoad1);


Note that tempLoad1 is declared at the start of the programme. I have also proved that this is not an issue.



Thanks in advance










share|improve this question
























  • 1) For better help sooner, post a Minimal, Complete, and Verifiable example or Short, Self Contained, Correct Example. 2) Java GUIs have to work on different OS', screen size, screen resolution etc. using different PLAFs in different locales. As such, they are not conducive to pixel perfect layout. Instead use layout managers, or combinations of them along with layout padding and borders for white space.
    – Andrew Thompson
    Nov 15 at 0:41










  • Q: What version of Java are you running? Q: What OS are you running it on?
    – paulsm4
    Nov 15 at 0:42










  • BTW - that code works just fine in an MCVE here. And it does that despite setting the bounds and the font (which is not used in any useful way). Post your own MCVE as an edit so we can see where it went wrong. (Voting to close.)
    – Andrew Thompson
    Nov 15 at 0:46










  • I'm not sure we actually need an MCVE: the problem is clear, and your code looks fine. I suspect it's just a "bad" .gif. SUGGESTION: get one of your .png files that "works", export it as a .gif, and see if the exported .gif displays. ALSO: I am curious about your Java version and your OS (on the off chance it might be relevant).
    – paulsm4
    Nov 15 at 0:50












  • "I'm not sure we actually need an MCVE:" Is that the royal 'we' @paulsm4? If not, don't speak for me. I'm certain the OP will not be getting my further attention until there is an MCVE in evidence.
    – Andrew Thompson
    Nov 15 at 1:00













up vote
2
down vote

favorite









up vote
2
down vote

favorite











I'm currently developing a programme which utilises gifs to indicate loading on the programme. However, I can not get the gif to appear on the JLabel after trying several ideas. I have tested many things, including the following.




  • Tried loading a png file instead of gif, this works, indicating no issue with the JLabel.

  • Tried loading the gif into a JLabel in a completely separate programme, this also works, indicating no issue with the gif.

  • Tried loading it in through URL AND through local resource, neither works.


The following snippet of code contains the main part of the declaration of the code. Any help is appreciated.



try {
URL URL = new URL("https://i.imgur.com/sMD9yUD.gif");
Icon Gif = new ImageIcon(URL);
tempLoad1.setIcon(Gif);
} catch (MalformedURLException e) {
e.printStackTrace();
}

tempLoad1.setHorizontalAlignment(SwingConstants.CENTER);
tempLoad1.setFont(new Font("Lato", Font.BOLD, 24));
tempLoad1.setBounds(63, 111, 452, 71);
contentPane.add(tempLoad1);


Note that tempLoad1 is declared at the start of the programme. I have also proved that this is not an issue.



Thanks in advance










share|improve this question















I'm currently developing a programme which utilises gifs to indicate loading on the programme. However, I can not get the gif to appear on the JLabel after trying several ideas. I have tested many things, including the following.




  • Tried loading a png file instead of gif, this works, indicating no issue with the JLabel.

  • Tried loading the gif into a JLabel in a completely separate programme, this also works, indicating no issue with the gif.

  • Tried loading it in through URL AND through local resource, neither works.


The following snippet of code contains the main part of the declaration of the code. Any help is appreciated.



try {
URL URL = new URL("https://i.imgur.com/sMD9yUD.gif");
Icon Gif = new ImageIcon(URL);
tempLoad1.setIcon(Gif);
} catch (MalformedURLException e) {
e.printStackTrace();
}

tempLoad1.setHorizontalAlignment(SwingConstants.CENTER);
tempLoad1.setFont(new Font("Lato", Font.BOLD, 24));
tempLoad1.setBounds(63, 111, 452, 71);
contentPane.add(tempLoad1);


Note that tempLoad1 is declared at the start of the programme. I have also proved that this is not an issue.



Thanks in advance







java swing jlabel gif






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 at 0:41









Andrew Thompson

152k27162336




152k27162336










asked Nov 15 at 0:38









JoeMaynard

2316




2316












  • 1) For better help sooner, post a Minimal, Complete, and Verifiable example or Short, Self Contained, Correct Example. 2) Java GUIs have to work on different OS', screen size, screen resolution etc. using different PLAFs in different locales. As such, they are not conducive to pixel perfect layout. Instead use layout managers, or combinations of them along with layout padding and borders for white space.
    – Andrew Thompson
    Nov 15 at 0:41










  • Q: What version of Java are you running? Q: What OS are you running it on?
    – paulsm4
    Nov 15 at 0:42










  • BTW - that code works just fine in an MCVE here. And it does that despite setting the bounds and the font (which is not used in any useful way). Post your own MCVE as an edit so we can see where it went wrong. (Voting to close.)
    – Andrew Thompson
    Nov 15 at 0:46










  • I'm not sure we actually need an MCVE: the problem is clear, and your code looks fine. I suspect it's just a "bad" .gif. SUGGESTION: get one of your .png files that "works", export it as a .gif, and see if the exported .gif displays. ALSO: I am curious about your Java version and your OS (on the off chance it might be relevant).
    – paulsm4
    Nov 15 at 0:50












  • "I'm not sure we actually need an MCVE:" Is that the royal 'we' @paulsm4? If not, don't speak for me. I'm certain the OP will not be getting my further attention until there is an MCVE in evidence.
    – Andrew Thompson
    Nov 15 at 1:00


















  • 1) For better help sooner, post a Minimal, Complete, and Verifiable example or Short, Self Contained, Correct Example. 2) Java GUIs have to work on different OS', screen size, screen resolution etc. using different PLAFs in different locales. As such, they are not conducive to pixel perfect layout. Instead use layout managers, or combinations of them along with layout padding and borders for white space.
    – Andrew Thompson
    Nov 15 at 0:41










  • Q: What version of Java are you running? Q: What OS are you running it on?
    – paulsm4
    Nov 15 at 0:42










  • BTW - that code works just fine in an MCVE here. And it does that despite setting the bounds and the font (which is not used in any useful way). Post your own MCVE as an edit so we can see where it went wrong. (Voting to close.)
    – Andrew Thompson
    Nov 15 at 0:46










  • I'm not sure we actually need an MCVE: the problem is clear, and your code looks fine. I suspect it's just a "bad" .gif. SUGGESTION: get one of your .png files that "works", export it as a .gif, and see if the exported .gif displays. ALSO: I am curious about your Java version and your OS (on the off chance it might be relevant).
    – paulsm4
    Nov 15 at 0:50












  • "I'm not sure we actually need an MCVE:" Is that the royal 'we' @paulsm4? If not, don't speak for me. I'm certain the OP will not be getting my further attention until there is an MCVE in evidence.
    – Andrew Thompson
    Nov 15 at 1:00
















1) For better help sooner, post a Minimal, Complete, and Verifiable example or Short, Self Contained, Correct Example. 2) Java GUIs have to work on different OS', screen size, screen resolution etc. using different PLAFs in different locales. As such, they are not conducive to pixel perfect layout. Instead use layout managers, or combinations of them along with layout padding and borders for white space.
– Andrew Thompson
Nov 15 at 0:41




1) For better help sooner, post a Minimal, Complete, and Verifiable example or Short, Self Contained, Correct Example. 2) Java GUIs have to work on different OS', screen size, screen resolution etc. using different PLAFs in different locales. As such, they are not conducive to pixel perfect layout. Instead use layout managers, or combinations of them along with layout padding and borders for white space.
– Andrew Thompson
Nov 15 at 0:41












Q: What version of Java are you running? Q: What OS are you running it on?
– paulsm4
Nov 15 at 0:42




Q: What version of Java are you running? Q: What OS are you running it on?
– paulsm4
Nov 15 at 0:42












BTW - that code works just fine in an MCVE here. And it does that despite setting the bounds and the font (which is not used in any useful way). Post your own MCVE as an edit so we can see where it went wrong. (Voting to close.)
– Andrew Thompson
Nov 15 at 0:46




BTW - that code works just fine in an MCVE here. And it does that despite setting the bounds and the font (which is not used in any useful way). Post your own MCVE as an edit so we can see where it went wrong. (Voting to close.)
– Andrew Thompson
Nov 15 at 0:46












I'm not sure we actually need an MCVE: the problem is clear, and your code looks fine. I suspect it's just a "bad" .gif. SUGGESTION: get one of your .png files that "works", export it as a .gif, and see if the exported .gif displays. ALSO: I am curious about your Java version and your OS (on the off chance it might be relevant).
– paulsm4
Nov 15 at 0:50






I'm not sure we actually need an MCVE: the problem is clear, and your code looks fine. I suspect it's just a "bad" .gif. SUGGESTION: get one of your .png files that "works", export it as a .gif, and see if the exported .gif displays. ALSO: I am curious about your Java version and your OS (on the off chance it might be relevant).
– paulsm4
Nov 15 at 0:50














"I'm not sure we actually need an MCVE:" Is that the royal 'we' @paulsm4? If not, don't speak for me. I'm certain the OP will not be getting my further attention until there is an MCVE in evidence.
– Andrew Thompson
Nov 15 at 1:00




"I'm not sure we actually need an MCVE:" Is that the royal 'we' @paulsm4? If not, don't speak for me. I'm certain the OP will not be getting my further attention until there is an MCVE in evidence.
– Andrew Thompson
Nov 15 at 1:00

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53310853%2fgif-not-appearing-in-jlabel%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53310853%2fgif-not-appearing-in-jlabel%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Can I use Tabulator js library in my java Spring + Thymeleaf project?