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

Thread: How Do i add pictures to a jframe?

  1. #1
    Member
    Join Date
    Jan 2012
    Posts
    107
    My Mood
    Grumpy
    Thanks
    6
    Thanked 2 Times in 1 Post

    Default How Do i add pictures to a jframe?

    i made a loading bar, basicly and im develpoing a program, can someone give me a basic on how to add it, it consist of 100+ pictures.


  2. #2
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: How Do i add pictures to a jframe?

    1.) Get the image first
    2.) get a lightweight container
    3.) override paintComponent
    4.) paint the image that you called

    im not sure if this is what you want

  3. #3
    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 Do i add pictures to a jframe?

    See
    Lesson: Working with Images (The Java™ Tutorials > 2D Graphics)
    How to Use Icons (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
    And you might want to do something about that signature....the all caps and animated flashing animation is beyond annoying (and could detract people from actually replying to your posts)

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

    chronoz13 (January 19th, 2012)

  5. #4
    Member DusteroftheCentury's Avatar
    Join Date
    Jan 2012
    Location
    Northern California
    Posts
    42
    My Mood
    Fine
    Thanks
    6
    Thanked 2 Times in 2 Posts

    Default Re: How Do i add pictures to a jframe?

    ImageIcon pic = new ImageIcon("Filename.extension");
    		panel.add(new JLabel(pic));
    this.setVisible(true);

    This should work.

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

    Java Programmer (January 21st, 2012)

  7. #5
    Member
    Join Date
    Jan 2012
    Posts
    107
    My Mood
    Grumpy
    Thanks
    6
    Thanked 2 Times in 1 Post

    Default Re: How Do i add pictures to a jframe?

    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
     
     
    public class Class2 extends JFrame {
     
     
     
    	public Class2(){
    		super("  ");
     
    		ImageIcon pic = new ImageIcon("ProgressBar000.PNG");
    		add(new JLabel(pic));
    		this.setVisible(true);
    	}
    }

    Picture dosent show up?

  8. #6
    Member DusteroftheCentury's Avatar
    Join Date
    Jan 2012
    Location
    Northern California
    Posts
    42
    My Mood
    Fine
    Thanks
    6
    Thanked 2 Times in 2 Posts

    Default Re: How Do i add pictures to a jframe?

    This should work.
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
     
    public class Class2 extends JFrame
     
    {
    	   public static void main(String[] args) {
    	        new Class2();
    	   }
     
    	public Class2()
    	{
     
    	this.setSize(300, 300);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setTitle("ImageTest");
        JPanel panel = new JPanel();
     
        JLabel label = new JLabel("ImageTest");
        panel.add(label);
        ImageIcon pic = new ImageIcon(Class2.class.getResource("ProgressBar000.png"));
        panel.add(new JLabel(pic));
     
        this.add(panel);
        this.setVisible(true);
    	}
    }

    Make sure the program has access to the file.ie put it in the projects bin folder.

    -Duster
    Last edited by DusteroftheCentury; January 19th, 2012 at 11:49 PM.

  9. The Following User Says Thank You to DusteroftheCentury For This Useful Post:

    Java Programmer (January 21st, 2012)

  10. #7
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: How Do i add pictures to a jframe?

    @DusteroftheCentury: Though you are trying to help others and that's why this community is but spoon feeding is one of the violations of the Forums rules if you read the rules.

  11. #8
    Member
    Join Date
    Jan 2012
    Posts
    107
    My Mood
    Grumpy
    Thanks
    6
    Thanked 2 Times in 1 Post

    Default Re: How Do i add pictures to a jframe?

    I Personally Don't Believe The Words "Spoon Feeding"

    I Asked "can someone give me a basic on how to add it" So He have me what i asked for, a understanding on how to add pictures into a JFrame.

    I Didn't Asked to be "spoon fed" i asked for help.

  12. #9
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: How Do i add pictures to a jframe?

    i asked for help
    i understand your part, i've been on that before, and up to now i still crave for exact answers for my problems, the term "Spoon feeding" was not yet , i can say implemented way back ago when i was on my very beginning of Java Programming, i got answers by code. I became inactive for years, when i got back, rules are strictly implemented including the Spoon feeding, i was thinking same as you are, "i just need answers(CODES) why CANT you give it?" thats the help that i need", but when i read the rules, i realize that, its better to solve your problems on your own, being a programmer its not like solving anything in an instant nor all at the same time, everything is step-by-step.

    think of this, "I want to learn integral calculus! give some example please!", if you dont even know how to add 1 + 1 or anything like advanced math like polynomials, how would you be able to solve that calculus? the point is, start from start dont start at the middle, if they give codes, would you be able to understand it all? what if you encounter a bug? a syntactical error? would be able to debug it on your own? I bet you WONT(Thats what i suffered when i got codes(Spoon Fed) even by our fellow professional forum mates) Because of the rules against spoon feeding , i learned how to be resourceful, google became my bestfriend, if i need codes, google can provide me, then if he doesnt, ill think of another solution, whats the benefit? i learned another thing,
    "Resourcefulness"

    ill give you an idea, your problem is "how to add picutres in JFrame", try to type it in google, exactly those words, he will throw you LOTS of references, when i say LOTS, its ALOT, and ill bet, one reference that google will gave you will refer to this site's tutorials and code snippets

    I Asked "can someone give me a basic on how to add it"
    you said the word "Basic", google can still provide you codes for that, you know the word basic, then you should start from there,


    i even got a problem right now, i dont have any big projects yet, so i decided to solve all available sorting algorithms that i know, i started with QuickSort, instead of asking the forums, "how to QuickSort", i typed in google, "QuickSort Algorithm procedure", and Boom! google gave tons of references, Codes, guides, pseudocode. At first glance, i dont understand the codes that im seeing, so i decided, to solve the Sorting by following the procedure, STEP-BY-STEP, and now im almost done, by trying to solve it in 5 days T_T, atleast, i can understand the flow of the algorithm, i even saw the Loopholes of the guides, it doesnt even state some of the important details. I even learned the term "PIVOT", the median-of-three, how to get it, the importance, things like that. After i finish it, its time to ask some here, if the thing that i did is efficient, then that s the time to take advantage of ONE OF the importance of forums.

    i hope you understand my point, english is not my native language, so im getting some problems expressing my thoughts, but i think its enough for you to understand it.

    please read this, youll enjoy this article
    http://www.javaprogrammingforums.com...n-feeding.html
    Last edited by chronoz13; January 21st, 2012 at 04:02 AM.

  13. #10
    Member DusteroftheCentury's Avatar
    Join Date
    Jan 2012
    Location
    Northern California
    Posts
    42
    My Mood
    Fine
    Thanks
    6
    Thanked 2 Times in 2 Posts

    Default Re: How Do i add pictures to a jframe?

    Ok, I understand.

    Ill go read the rules.

    Where exactly are they located?
    Last edited by DusteroftheCentury; January 21st, 2012 at 11:39 AM.

  14. #11
    Member
    Join Date
    Jan 2012
    Posts
    107
    My Mood
    Grumpy
    Thanks
    6
    Thanked 2 Times in 1 Post

    Default Re: How Do i add pictures to a jframe?

    I Googled it, Read everything in my Java Programming Book and i couldn't get it to work, i don't use Java Programming Forums as my first source of help.

Similar Threads

  1. Java animation using pictures help
    By NekoSH0GUN in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 1st, 2011, 11:49 AM
  2. Importing gif/pictures
    By javanerd in forum Java Theory & Questions
    Replies: 2
    Last Post: October 31st, 2010, 11:58 PM
  3. pictures wont load
    By wolfgar in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 14th, 2010, 09:34 AM
  4. New Forum Avatar Pictures
    By JavaPF in forum The Cafe
    Replies: 0
    Last Post: February 14th, 2009, 12:15 PM
  5. How to animate pictures using JCreator?
    By bil_Imma in forum AWT / Java Swing
    Replies: 6
    Last Post: February 13th, 2009, 07:00 AM