Article View: borland.public.jbuilder.java.api
Article #1225Re: how do I draw a JPG to a panel/container
From: vkoni
Date: Mon, 15 Apr 2002 18:49
Date: Mon, 15 Apr 2002 18:49
50 lines
2472 bytes
2472 bytes
yes you can. I assume that you are trying to have 'colorfull' containter. I
also assume that you still want to use your container to fill it with other
compontents while picture is under them.
Ok - it is not naturally supported by java but I did a little trick:
Declare a new Containter class (JPanel, JDialog etc.) and overide public
void paint ( Graphics g ) method as shown:0
public class PanelP extends JPanel {
// BACKGROUND IMAGE -----------------------
static ImageIcon imageBack = <load your image here>
// ----------------------------------------
// Constructor
public PaneP {
// ------------------------------------------------
// add your components here --------------------
// ------------------------------------------------
}
/** Painting picture */
public void paint ( Graphics g ) {
// super.paint( g ) ; // (see below)
g.drawImage (imageBack.getImage(), 0, 0, this );
}
}
Then try WITH or WITHOUT (in this example commented) super.paint(g) - at the
begining OR at the end of the paint mathod (see what will work).
If you still have problems, contact me at ivko999@yahoo.com
Hope I helped
"PeterH" <!Sorry-TooMuchSpam!nope@nope.com> wrote in message
news:3cb9ef73$1_1@dnews...
> I thought I could just use a drawImage() method, but I can't seem to get
it
> to work. I can get it to work if I use an Icon and a JLabel, but I was
> hoping to avoid using a JLabel for an image.
>
> Can I draw an image to a container? Thanks.
>
>
Technical Details
Message-ID:
<a9f7t5$2on3r$1@ID-133850.news.dfncis.de>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!supernews.com!isdnet!news-fra.pop.de!news-fra1.dfn.de!fu-berlin.de!uni-berlin.de!ppp65-166.verat.NET!not-for-mailReferences:
<3cb9ef73$1_1@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,422c9cef40be2392 X-Google-Attributes: gid1089d0,public X-Google-ArrivalTime: 2002-04-15 11:59:30 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!supernews.com!isdnet!news-fra.pop.de!news-fra1.dfn.de!fu-berlin.de!uni-berlin.de!ppp65-166.verat.NET!not-for-mail From: "vkoni" <ivko999@yahoo.com> Newsgroups: borland.public.jbuilder.java.api Subject: Re: how do I draw a JPG to a panel/container Date: Mon, 15 Apr 2002 20:49:40 +0200 Lines: 52 Message-ID: <a9f7t5$2on3r$1@ID-133850.news.dfncis.de> References: <3cb9ef73$1_1@dnews> NNTP-Posting-Host: ppp65-166.verat.net (217.26.65.166) X-Trace: fu-berlin.de 1018897126 2907259 217.26.65.166 (16 [133850]) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200