File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes urgent help with adding an image to jframe Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "urgent help with adding an image to jframe" Watch "urgent help with adding an image to jframe" New topic
Author

urgent help with adding an image to jframe

john mattucci
Ranch Hand

Joined: Nov 03, 2000
Posts: 331
I`m trying to add a background to a JFrame as a wallpaper the problem im having is that
the image appears in the centre of the frame and I cant seem to figure out how to make it
cover(the image) the entire frame and for the image to be able to resize if i were to
maximize or minimize the frame
background = new JLabel(new ImageIcon("c:\\windows\\desktop\\bg0063.jpg"));
getContentPane().add(background)
where do I go from here
Grant Crofton
Ranch Hand

Joined: Nov 08, 2000
Posts: 154
I haven't used SWING, but it looks like the problems you get are because of how you draw the image - it's part of a JLabel, which gets put in the centre of the frame.
You could try setting the frame's layout to a FlowLayout, so it gets put at the start, with something like

NOTE: I'm guessing that's how you use getContentPane(), but I've not used it, so somebody pls correct me if I'm wrong.
You might be better off drawing the image yourself in the JFrame's paint().
It would go something like this:

I haven't tested that code, but I think it's right.
Then you can go into scaling the image according to the size of the frame, etc.
One thing you might get with that is the frame title & sides cover some of the Image - if this happens, use

in your paint().
Hope that helps.
gautham kasinath
Ranch Hand

Joined: Dec 01, 2000
Posts: 583
Hi!
Well have u tried to place the JLabel with the start position and the width and height with setBounds(int x, int y, int width, int height); .. well I guess that should help.
ne way lemme know if that works.
If it doesnt I shall try n find a work around for u r problem..
All the best
Regds
Gautham Kasinath


"In the country of the blind, the one eyed man is the King"
Gautham Kasinath CV at : http://www.geocities.com/gkasinath
Frank Hale
Ranch Hand

Joined: Mar 25, 2000
Posts: 230
There is a code snippet at
http://codeguru.earthweb.com/java/articles/179.shtml
which shows how to add a background image to a JTree. It tiles it nicely like you want. I wonder if there is something in that code you could use to do the same for your JFrame.
Hope this helps!
Frank
 
Consider Paul's rocket mass heater.
 
subject: urgent help with adding an image to jframe
 
Similar Threads
how to add background image, Header image, three label and three text box in JFrame
Setting an image as a background of a JFrame
To Display background image in a Jframe/JPanel
Looking at basic game design
swing