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
java swing jlabel gif
|
show 2 more comments
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
java swing jlabel gif
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
|
show 2 more comments
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
java swing jlabel gif
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
java swing jlabel gif
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
|
show 2 more comments
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
|
show 2 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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