I have created one GUI using Swing of Java. I have to now set one sample.jpeg image as a background to the frame on which I have put my components.How to do that ?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is no concept of a “background image” in a
JPanel, so one would have to write their own way to implement such a feature.One way to achieve this would be to override the
paintComponentmethod to draw a background image on each time theJPanelis refreshed.For example, one would subclass a
JPanel, and add a field to hold the background image, and override thepaintComponentmethod:(Above code has not been tested.)
The following code could be used to add the
JPanelWithBackgroundinto aJFrame:In this example, the
ImageIO.read(File)method was used to read in the external JPEG file.