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.


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

Results 1 to 2 of 2

Thread: Inserting Image Help

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Thanked 0 Times in 0 Posts

    Default Inserting Image Help

    I need help inserting a picture, I would like the picture centered and on top of the JPanel above "JLabel Header 1"...where and how would i do this? I have this so far:

    ImageIcon icon = new ImageIcon ("Taxi.jpg");
    JPanel Driver1 = new JPanel();
    Driver1.setPreferredSize (new Dimension(175, 125));
    Driver1.setBackground (Color.green);
    JLabel Header1 = new JLabel ("Name: " + fName + " " + lName);
    JLabel MPG = new JLabel ("MPG: " + fmt.format(mpg));
    JLabel FPM = new JLabel ("Fares per mile: " + cfmt.format(fpm));
    JLabel GPPM = new JLabel ("Gas paid per mile: " + cfmt.format(gppm));
    JLabel PROFIT = new JLabel ("Total Profit: " + cfmt.format(profit));
    Driver1.add (Header1);
    Driver1.add (MPG);
    Driver1.add (FPM);
    Driver1.add (GPPM);
    Driver1.add (PROFIT);

  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Thanked 833 Times in 772 Posts
    Blog Entries

    Default Re: Inserting Image Help

    Try using a different layout or combinations of them. For example, BoxLayout should let you do this.
    JPanel vertPanel = new JPanel();
    vertPanel.setLayout(new BoxLayout(vertPanel, BoxLayout.PAGE_AXIS));

Similar Threads

  1. Image problems
    By Bekuraryou1228 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 19th, 2010, 05:53 PM
  2. Background image on GUI
    By OBLITERATOR in forum AWT / Java Swing
    Replies: 3
    Last Post: March 5th, 2010, 12:10 PM
  3. Array to image
    By oxxxis in forum Collections and Generics
    Replies: 1
    Last Post: January 19th, 2010, 06:46 PM
  4. Pixel Alteration in an image/image rotation
    By bguy in forum Java Theory & Questions
    Replies: 3
    Last Post: November 1st, 2009, 10:50 AM
  5. How images stores in awt.Image class?
    By BharatT in forum AWT / Java Swing
    Replies: 0
    Last Post: February 24th, 2009, 05:10 AM