using the java swing how can i put a background image to my application in a way that the image will cover the frame .
ps : I'm new to the java so maybe my question is a silly one but i will appreciate any help .
jouj 3 Newbie Poster
jackbauer24 commented: crawl before you walk... the question is not silly :) +3
Recommended Answers
Jump to PostThat is pretty easy. An example is here:-
import java.awt.*; import javax.swing.*; class <your className> { Image im = new ImageIcon("Yourimage.jpeg/png").getImage(); JFrame frame; public static void main(String[] args) { <your className> y = new <your className>(); y.go(); } public void go() { /*normal GUI code would appear …
Jump to PostPlease post the full text of the error message.
Jump to PostYou declare im and frame inside the constructor ImageBackGround(), so they can't be accessed from anywhere else. If you want them available to all the methods of that class then declare them in the class but outside any one method.
Jump to PostTwo small suggestions...
new ImageIcon("file name")
is certainly convenient, but it throws no Exceptions if it fails, thus leading to confusing errors later on when you try to use the image. It's a good idea to check the resulting Image, egim.getWidth(null)>0
and issue a diagnostic if necessaryIf …
All 14 Replies
jackbauer24 0 Junior Poster
jouj 3 Newbie Poster
mKorbel 274 Veteran Poster
NormR1 563 Posting Sage Team Colleague
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
jackbauer24 commented: You almost solved the whole issue! +3
jackbauer24 0 Junior Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
vikrammalik 0 Newbie Poster
zeroliken 79 Nearly a Posting Virtuoso
jackbauer24 0 Junior Poster
jouj 3 Newbie Poster
NormR1 563 Posting Sage Team Colleague
jouj 3 Newbie Poster
NormR1 563 Posting Sage Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.