Board index » jbuilder » [image background] add image as a background in JPanel

[image background] add image as a background in JPanel


2004-04-08 12:26:46 PM
jbuilder11
is it possible to add an image as a background to a JPanel that has some
buttons and textfields ?
or any similar idea,
Thanks so much
raydog
 
 

Re:[image background] add image as a background in JPanel

On 4/8/2004 at 12:26:46 AM, Raydog wrote:
Quote
is it possible to add an image as a background to a JPanel that
has some buttons and textfields ?
Override the JPanel paintComponent() method and draw the image in
whatever manner you want. For example, the following code draws an
image, stretched to fill the panel:
public void paintComponent( Graphics g ) {
Dimension size = getSize();
Insets insets = getInsets();
int width = size.width - insets.left - insets.right;
int height = size.height - insets.top - insets.bottom;
if ( (image != null) && (image.getHeight(this)>0) ) {
g.drawImage( image, insets.left, insets.top,
width, height, this );
}
}
--
Regards,
John McGrath [TeamB]
---------------------------------------------------
Before sending me e-mail, please read:
www.JPMcGrath.net/newsgroups/e-mail.html