How to change an Imagepath
Hey,
I am trying to change the file path for an image. What i had planned was an if function that would switch the path name, because at the moment i have a bunch of labels with a picture, and clicking the button makes on invisible and the other visible. The main problem is that i have a bunch of space in my JFrame that is being used by a bunch of picture that people cant see, so if i switch it to one pic and just switch the path for it it would save the space...
Is there a method for this, or another way to get around the open space?
Thanks
Re: How to change an Imagepath
I don't know what you are asking...how does changing the image path directly relate to its visibility in a user interface? It seems you are having trouble arranging components and JLabels in a JFrame? Look at using one or a combination of LayoutManagers, which will help you manage the space and placement of the Images.
A Visual Guide to Layout Managers (The Java™ Tutorials > Creating a GUI With JFC/Swing > Laying Out Components Within a Container)
Re: How to change an Imagepath
Hi,
Im not having troubles with layouts. The thing is at the moment i have multiple pictures. Instead i only want to have one picture that changes. I thought that by changing the path i could change the picture. I would have a button that would change the picture. Does that make more sense?
Re: How to change an Imagepath
If each picture corresponds to a file, create different ImageIcon's, and add one to a JLabel. When you want to change the image, call setIcon() on the JLabel with the new ImageIcon corresponding to the image you wish to change to.