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

Thread: Cant get background image to take up whole panel

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Cant get background image to take up whole panel

    So, basically, I have created my picture using this:

    private static JPanel testpic = new JPanel() {
             ImageIcon backImage = new ImageIcon("src/bc.jpg");
             Image image = backImage.getImage();
             {setOpaque(false);}
             //Override
             public void paintComponent (Graphics g) {
               g.drawImage(image, 0, 0, this);
               super.paintComponent(g);
             }
           };

    As you can see I named my panel "testpic". I later on added testpic to my frame, and before that added a label to my testpic. The label shows up fine, and its background is set to my picture. The only problem is that my picture ONLY takes up the space of my label. Instead of expanding and filling up the whole panel like a background should do, it is more like a tiny background for my label. Can anyone tell me how to fix this? Thanks in advance!


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Cant get background image to take up whole panel

    Take a look at the Graphics API for useful functions that let you specify an image's width and height when drawing it.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Adding components to my GUI over a background image
    By derekxec in forum AWT / Java Swing
    Replies: 12
    Last Post: August 23rd, 2011, 03:01 PM
  2. Background image trouble on GUI.
    By Pydra in forum AWT / Java Swing
    Replies: 2
    Last Post: July 7th, 2011, 11:44 AM
  3. Need help adding background image (noob here)
    By OpX316 in forum AWT / Java Swing
    Replies: 18
    Last Post: July 7th, 2011, 09:10 AM
  4. Is it possible to make a background to in image transparent
    By Zein in forum Java Theory & Questions
    Replies: 10
    Last Post: June 13th, 2011, 04:18 AM
  5. Background image on GUI
    By OBLITERATOR in forum AWT / Java Swing
    Replies: 3
    Last Post: March 5th, 2010, 12:10 PM

Tags for this Thread