aspose file tools*
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
Author

jPanel background image help!

Gabriel Pedraza
Greenhorn

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) {
g.drawImage(background,0,0,this);

}
};

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?
Thanks!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
"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.

CR
[ May 28, 2008: Message edited by: Campbell Ritchie ]
 
Consider Paul's rocket mass heater.
 
subject: jPanel background image help!