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 8 of 8

Thread: image display in java

  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    5
    Thanks
    2
    Thanked 1 Time in 1 Post

    Question image display in java

    i would like to know how to display a picture upon clicking a button..

  2. The Following User Says Thank You to Rakshith For This Useful Post:

    javanand (June 25th, 2013)


  3. #2
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    571
    My Mood
    Sleepy
    Thanks
    9
    Thanked 84 Times in 78 Posts

    Default Re: image display in java

    Use an ActionListener for the button, load the image and display it in a JLabel.

  4. The Following User Says Thank You to PhHein For This Useful Post:

    Rakshith (June 25th, 2013)

  5. #3
    Member Cronus's Avatar
    Join Date
    Feb 2013
    Location
    Gothenburg, Sweden
    Posts
    41
    My Mood
    Inspired
    Thanks
    6
    Thanked 7 Times in 6 Posts

    Default Re: image display in java

    You'll have to use multiple libraries, awt and swing. Here's some easy anti-OOP code I created for you:

    ...

    If you don't understand something. feel free to ask me. Also, you should create a folder in the project (if you're using an IDE) called "res". This is where you put your images/etc. Then, to tell Java were the image is, simply write "res/image.png". Take note that actionPerformed cannot be placed in the main.

    Feel free to hit the "Thanks" (displayed to the left of the screen below my info) or something. This is the first time I'm helping someone out with code!

    Note: This thread does not belong to "What's wrong with my code?". Consider moving it to Java Theory & Questions!
    Last edited by Cronus; June 24th, 2013 at 05:49 PM. Reason: EDIT: Shortened several comments + changed sentences and made them more understandable

  6. The Following User Says Thank You to Cronus For This Useful Post:

    Rakshith (June 25th, 2013)

  7. #4
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    571
    My Mood
    Sleepy
    Thanks
    9
    Thanked 84 Times in 78 Posts

    Default Re: image display in java

    Great spoon feeding!

  8. #5
    Member Cronus's Avatar
    Join Date
    Feb 2013
    Location
    Gothenburg, Sweden
    Posts
    41
    My Mood
    Inspired
    Thanks
    6
    Thanked 7 Times in 6 Posts

    Default Re: image display in java

    Quote Originally Posted by PhHein View Post
    Great spoon feeding!
    My thoughts exactly!

  9. #6
    Junior Member
    Join Date
    May 2013
    Posts
    5
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: image display in java

    thanks a lot i would like to let you know,dat iam familar with java ide,iam using eclipse currently as iam still a beginner.will implement the code and build on it.
    will surely contact you if i had any further doubts.
    thanks a lot

  10. #7
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,225
    Thanks
    176
    Thanked 817 Times in 760 Posts
    Blog Entries
    5

    Default Re: image display in java

    Quote Originally Posted by PhHein View Post
    Great spoon feeding!
    Indeed. Cronus, I do recommend reading
    Announcements - What's Wrong With My Code?
    and
    The Problem with Spoon-feeding

  11. #8
    Member Cronus's Avatar
    Join Date
    Feb 2013
    Location
    Gothenburg, Sweden
    Posts
    41
    My Mood
    Inspired
    Thanks
    6
    Thanked 7 Times in 6 Posts

    Default Re: image display in java

    I know what it is, I got a little excited to make example code to someone for the first time. "My thoughts exactly" wasn't maybe the most correct answer, but I have something to say in my defense: "#YOLO #SWAG". I rest my case.

    --- Update ---

    I'm glad to help. Spoon feeding is illegal in 42 countries, though. So you'll have to make it by yourself next time.

Similar Threads

  1. Image in Java will not display
    By Shaw2380 in forum What's Wrong With My Code?
    Replies: 13
    Last Post: March 30th, 2013, 08:50 PM
  2. Why won't this image display?
    By mkrage in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 3rd, 2012, 09:05 PM
  3. Help with image display on JTextArea
    By mozart66 in forum AWT / Java Swing
    Replies: 4
    Last Post: May 18th, 2012, 09:35 AM
  4. Image Doesn't Display with Qualified Image Path????
    By swaginator in forum What's Wrong With My Code?
    Replies: 5
    Last Post: March 31st, 2012, 12:29 AM
  5. Can't display an image...
    By barebackingtiger in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 25th, 2012, 06:21 PM