Forums Register Login

Image not showing up in GUI

+Pie Number of slices to send: Send
I have looked at several tutorials online and have looked at a couple forums as well but I cannot get my image to display on my GUI. I know it has something to do with the path but even after trying to research it I still have no clue on how to fix it. I would greatly appreciate any pointers on how to fix this problem.

Here is my code. I apologize for it not being in the best format.



[Edited to add code tags and remove unnecessary blank lines. CR]
+Pie Number of slices to send: Send
Hi Madison,

always a nasty thing, getting these relative paths correct.

As a quick way to check whether there's anything wrong whatsoever, what I would do is to use the complete
path of the image in your ImageIcon creation.

say fullpath is a String containing the path to your image. The easiest way to get that is to use the Windows Navigator,
or the equivalent of your OS. Go to your image, and copy the adress from the address bar. Say it is c:\myImages.

Then in your code you say:

Now, this must work, since I cannot find anything wrong with your code.

I don't see you using any package statement, so let's leave that for now.

Greetings,
Piet
+Pie Number of slices to send: Send
And welcome to the Ranch

Always use the code button, which makes code look much better, particularly if it has short lines and good indentation. I shall try to edit your post shortly, and see if I can improve it
this llama doesn't want your drama, he just wants this tiny ad for his mama
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 4402 times.
Similar Threads
How to change color of a content pane after using borderlayout
How to refresh the JButton text among other things.
GUI / EventListener Problem
Troubleshooting an ActionListener
Problem Updating a JButton
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 22:28:55.