jQuery in Action, 3rd edition
The moose likes Swing / AWT / SWT and the fly likes jPanel background image help! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "jPanel background image help!" Watch "jPanel background image help!" New topic

jPanel background image help!

Gabriel Pedraza

Joined: May 28, 2008
Posts: 1
Hi, i have a simple applet with two jPanel components. I use the first one to display a background image for the whole applet, and is working quite nicely. Inside this jPanel i have some buttons, labels, jTable, etc. and all is working fine. The problem is that i have a secondary jPanel in which i also need to display an image (much smaller that the background of the applet) but i cannot manage to get it drawn in the screen. Here is the sample code i am using:

jPanel1 = new javax.swing.JPanel() {
protected void paintComponent(Graphics g) {


jPanel2 = new javax.swing.JPanel(){
protected void paintComponent(Graphics g) { g.drawImage(coverArt.getScaledInstance(100,100,Image.SCALE_DEFAULT),0,0,this);

The result is that im having the image of the first jPanel always drawn but i cannot see the image in the second jPanel at all. Any ideas?
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46397
"gpedraza," when you logged on you appear to have missed the naming policy which requires first name-space-last name. We do actually insist on that, so please go to "my profile" and correct your displayed name to comply.

[ May 28, 2008: Message edited by: Campbell Ritchie ]
I agree. Here's the link: http://aspose.com/file-tools
subject: jPanel background image help!
It's not a secret anymore!