🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #12933

Re: Problem with drawing in JPanel

#12933
From: Mikael Lindkvist
Date: Thu, 22 Oct 1998 00:00
44 lines
2030 bytes
Anne,

 Normally the superclass take care of  painting the background but since
you are overriding the paintComponent method the superclass can't  do it
for you. So you can paint the background yourself  with something like:

public void paintComponent(Graphics g)
    {
        Dimension d = this.getSize();
        g.setColor(Color.pink);
        g.fillRect(0, 0, d.width, d.height);
        g.setColor(Color.black);
        g.drawString("hello", 50,50);
    }

 or let the superclass do it:

public void paintComponent(Graphics g)
   {
     super.paintComponent(g);
     g.setColor(Color.black);
     g.drawString("hello", 50,50);
   }

/Mikael Lindkvist

Anne JANSSENS wrote:

>  Hi, here is my problem :I want to draw in a JTable, where I have
> already put a button.I rewrite the method paintComponent, but the
> color of the backgroundbecome every times grey instead of any color,
> why ? Thanks for any suggestions, Anne Here is the code of my program
> : import com.sun.java.swing.*;import java.awt.*;public class un_panel
> extends JPanel
> {    public un_panel()
>    { this.setLayout(new BorderLayout());
>      this.setBackground(Color.pink);                   // i want the
> panel to be in pink color
>      JButton un_bouton=new JButton("hello");
>      this.add(un_bouton,"North");
>    }    public void paintComponent(Graphics g)
>    { g.setColor(Color.black);
>      g.drawString("hello", 50,50);    }
> }
Technical Details
Message-ID: <362ED490.B9BEBE8C@infodata.sema.se>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <70kkt2$hfp6@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,74df4fde9fb2834
X-Google-Attributes: gid111d45,public
From: Mikael Lindkvist <mikael.lindkvist@infodata.sema.se>
Subject: Re: Problem with drawing in JPanel
Date: 1998/10/22
Message-ID: <362ED490.B9BEBE8C@infodata.sema.se>
X-Deja-AN: 403833705
Content-Transfer-Encoding: 7bit
References: <70kkt2$hfp6@forums.borland.com>
Content-Type: text/plain; charset=us-ascii
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing