To set the background image on JFrame, there is no such direct methods as setBackground(). So we have to build our own interfaces to do that. Here is an example which uses the JPanel swing component to set the Background Image.
Click here to view the code
or
Click here : JFrameBackgroundImage
Fig : shows the screen when you run the above code. you need to have an image named "image.jpg" for the background image to be placed in the same directory/folder where the class file resides.
Tuesday, March 25, 2008
Setting the Background Image on JFrame
Labels:
JFrame Background Image
Subscribe to:
Post Comments (Atom)
11 comments:
thanks for your example!
But i am not able to maximize the screen. so cant view the image.
I think it would be better if you kept the reference of the image in the JPanel class, instead of creating the image in every call of paintComponent.
>>
Image img = new ImageIcon("image.jpg").getImage();
Awesome! Thats a very useful example.
@Sindhu: The setResizable(false) in the code has to be commented to enable frame resizing.
thanks for your code
Thankies sooooo much!
Hi I run ur code but its not showing any Image in backgroung an u help me plz......
Thanks!It is easy to understand for me to sharpen my java.
Thanks!It is easy to understand for me to sharpen my java.
@neerav, but everyone should know this--
you have to have the file in your project folder first before your program can recognize the file
Post a Comment