Dear all, I want to apply a image to the background of a JPanel. The JPanel is having 5 Buttons on it arranged vertically in a null layout. I tried applying a image to it by using g.drawImage in the paintComponent. It drew the image but the image was not properly distorted. It was not displayed in parts where there was a button on the JPanel. Can anybody please tell me how to display an image properly behind the buttons on a JPanel. Please this is URGENT. Thanks
Hi Anirban, I may be wrong, but I couldn't find any methods in the java docs that set the background of a JPanel to a graphic image, inherited methods or otherwise. I did find methods which let you add a graphic image to either a JLabel,(a Swing component) or a JFrame, (an awt component). Would either of these work for you?
Joined: Aug 08, 2002
Dear Leo, Thanks for your reply, but that will not work, as we cannot add any components to the frame or JLabel directly.
Take a look at my brief article "Displaying Background Images with Swing" at http://www.conceptgo.com/articles/DisplayBackground.html off conceptGO's community page. I think it will give you the information you need, although I'm a little confused by your statement "It was not displayed in parts where there was a button on the JPanel."