Thread View: borland.public.jbuilder.java.swing
2 messages
2 total messages
Started by Raydog
Thu, 08 Apr 2004 04:26
[image background] add image as a background in JPanel
Author: Raydog
Date: Thu, 08 Apr 2004 04:26
Date: Thu, 08 Apr 2004 04:26
8 lines
1076 bytes
1076 bytes
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
Author: 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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads