I am trying to place an image as a JLabel into my JFrame. The spacing in the JFrame indicates that the space for the image is there but the image just does not get displayed. There is no exception thrown.
Thanks for the reply. I know this because there are other JLabels in the JFrame and there is a gap of the expected size among the other JLabels. If I comment out the errant JLabel the gap goes away. I will try to reproduce the problem in an SSCCE and post it.
P.S. I am aware of the programming standards but this was one of the first things I wrote in Java and never got around to fixing it. Until now.
Here is a sanitized SSCCE that does indeed reproduce the problem.
I don't know if the image itself is the problem but since it is not available via a URL, I don't know how to upload it or if that is even necessary. My guess is that any image would yield the same result. At least it does for me.
Thanks again for the reply. I am not sure I completely understood what you were asking me to do but here is what I did:
1) Removed all setBounds.
2) Changed the layout manager from null to FlowLayout:
The result was a panel that initially only showed the title bar. I had to resize it to see what was in it. I am guessing that you did not mean for me to remove the setBounds on the JFrame just on all the JLabels. The result was still no image and the other JLabels were run together (not unexpected). I'm not concerned with that part as I can adjust it all once I get the image showing up. In this case however, there was no "extra" space where the image should have been, FWIW.
After playing with this a bit more to no avail, I am wondering if I have the file path correct. Where files are relative to the class file is still a little mysterious to me. The jpg is in the same directory as the class referencing it. Thus I don't specify anything other than the file name. Is that correct? Would I get an exception if the file was not found? If not, is there a way to verify the file path?