🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Problem with drawing in JPanel

#12928
From: Anne JANSSENS
Date: Wed, 21 Oct 1998 00:00
85 lines
3284 bytes
Message en plusieurs parties et au format MIME.

------=_NextPart_000_000B_01BDFD01.89EC47C0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

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 background
become 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=3Dnew JButton("hello");
     this.add(un_bouton,"North");
   }

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

   }
}

------=_NextPart_000_000B_01BDFD01.89EC47C0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
<HTML>
<HEAD>

<META content=3Dtext/html;charset=3Diso-8859-1 =
http-equiv=3DContent-Type>
<META content=3D'"MSHTML 4.72.2106.6"' name=3DGENERATOR>
</HEAD>
<BODY>
<DIV>Hi, here is my problem :</DIV>
<DIV>I want to draw in a JTable, where I have already put a =
button.</DIV>
<DIV>I rewrite the method paintComponent, but the color of the =
background</DIV>
<DIV>become every times grey instead of any color, why ?</DIV>
<DIV>&nbsp;</DIV>
<DIV>Thanks for any suggestions, Anne</DIV>
<DIV>&nbsp;</DIV>
<DIV><EM><U>Here is the code of my program :</U></EM></DIV>
<DIV>&nbsp;</DIV>
<DIV>import com.sun.java.swing.*;</DIV>
<DIV>import java.awt.*;<BR></DIV>
<DIV>public class un_panel extends JPanel<BR>{</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp; public un_panel()<BR>&nbsp;&nbsp; { this.setLayout(new =

BorderLayout());<BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
this.setBackground(Color.pink);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
<EM>// i want the panel to be in pink =
color<BR></EM>&nbsp;&nbsp;&nbsp;&nbsp;=20
JButton un_bouton=3Dnew =
JButton(&quot;hello&quot;);<BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
this.add(un_bouton,&quot;North&quot;);<BR>&nbsp;&nbsp; }</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp; public void paintComponent(Graphics g)<BR>&nbsp;&nbsp; =
{=20
g.setColor(Color.black);<BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
g.drawString(&quot;hello&quot;, 50,50);</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp; }<BR>}</DIV></BODY></HTML>

------=_NextPart_000_000B_01BDFD01.89EC47C0--
Technical Details
Message-ID: <70kkt2$hfp6@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,74df4fde9fb2834,start
X-Google-Attributes: gid111d45,public
From: "Anne JANSSENS" <recherche@generix.fr>
Subject: Problem with drawing in JPanel
Date: 1998/10/21
Message-ID: <70kkt2$hfp6@forums.borland.com>
X-Deja-AN: 403532012
Content-Type: multipart/alternative; boundary="----=_NextPart_000_000B_01BDFD01.89EC47C0"
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing