Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: How to change an Imagepath

  1. #1
    Member
    Join Date
    Sep 2011
    Posts
    46
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default 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)

  3. #3
    Member
    Join Date
    Sep 2011
    Posts
    46
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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?

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default 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.

Similar Threads

  1. Making change
    By Jerick in forum Algorithms & Recursion
    Replies: 3
    Last Post: October 7th, 2011, 06:49 PM
  2. Trying to Give Coins For Change
    By bengregg in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 27th, 2011, 04:21 PM
  3. [SOLVED] Can't get boolean to change!!
    By Day2Day in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 2nd, 2010, 07:20 PM
  4. Change to JOptionPane
    By Liuric in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 1st, 2010, 12:07 AM
  5. [SOLVED] Change the size of an image
    By subhvi in forum Algorithms & Recursion
    Replies: 4
    Last Post: August 23rd, 2009, 11:44 PM