Article View: borland.public.jbuilder.java.swing
Article #1122Re: [image background] add image as a background in JPanel
From: John McGrath [TeamB]
Date: Thu, 08 Apr 2004 19:43
Date: Thu, 08 Apr 2004 19:43
29 lines
1875 bytes
1875 bytes
On 4/8/2004 at 12:26:46 AM, Raydog wrote:
> 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:
http://www.JPMcGrath.net/newsgroups/e-mail.html
Technical Details
Message-ID:
<40759d49@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!in.100proofnews.com!in.100proofnews.com!news02.tsnz.net!newsfeed01.tsnz.net!news.xtra.co.nz!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<4074d629@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,ba42f89a258b8cc4 X-Google-Attributes: gid111d45,public X-Google-ArrivalTime: 2004-04-08 11:53:05 PST From: "John McGrath [TeamB]" <ng-b@JPMcGrath.net> Subject: Re: [image background] add image as a background in JPanel Newsgroups: borland.public.jbuilder.java.swing References: <4074d629@newsgroups.borland.com> User-Agent: XanaNews/1.16.2.2 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 NNTP-Posting-Host: 151.197.30.87 Message-ID: <40759d49@newsgroups.borland.com> Date: 8 Apr 2004 11:43:21 -0800 X-Trace: newsgroups.borland.com 1081449801 151.197.30.87 (8 Apr 2004 11:43:21 -0800) Lines: 29 X-Authenticated-User: jpmcgrath Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!in.100proofnews.com!in.100proofnews.com!news02.tsnz.net!newsfeed01.tsnz.net!news.xtra.co.nz!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail