🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: be.comp.programming
Article #12955

Re: Question: drawing on JPanel II (How to get the lower right corner)

#12955
From: Jon A. Cruz
Date: Sat, 22 Sep 2001 18:43
40 lines
2523 bytes
Nick de Graeve wrote:

> Hi
>
> I want to draw a rectangle at 20 pixels of the borders of a JPanel and I use
> the getWidth() and getHeight() methods to get the lower right corner but the
> rectangle gets drawn beyond the lower and right edges of the JPanel. I got a
> class that extends JPanel and has following paintComponent method:
>
>   public void paintComponent(Graphics g) {
>      Graphics g2 = (Graphics)g;
>      super.paintComponent(g2);
>      g2.drawRect(20, 20, getWidth()-20, getHeight()-20);
>      }
>
> What am I doing wrong?

(follow-ups set)

First of all, please don't cross-post indiscriminately.
http://foldoc.doc.ic.ac.uk/foldoc/foldoc.cgi?query=netiquette


Secondly, when using Swing, you shouldn't be doing things directly like that.
Hardcoding numbers is usually a bad thing. Have you taken into account any
border on the JPanel, etc?

Also... what color are you trying to draw in? You don't set any.




--
Jon A. Cruz (former Sergeant, U.S. Army)

"They that can give up essential liberty to obtain a little temporary
safety deserve neither liberty nor safety." - Benjamin Franklin

http://www.forbes.com/2001/09/17/0917lie.html
http://slashdot.org/article.pl?sid=01/09/16/1647231&mode=thread
Technical Details
Message-ID: <3BACDBE7.A255632F@geocities.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!sn-xit-01!sn-post-02!sn-post-01!supernews.com!corp.supernews.com!not-for-mail
References: <CN3r7.65846$6x5.14500406@afrodite.telenet-ops.be>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 113ae9,645be76798212a49
X-Google-Attributes: gid113ae9,public
X-Google-Thread: 10a146,645be76798212a49
X-Google-Attributes: gid10a146,public
X-Google-Thread: 10fd6d,645be76798212a49
X-Google-Attributes: gid10fd6d,public
X-Google-Thread: fcea4,645be76798212a49
X-Google-Attributes: gidfcea4,public
X-Google-ArrivalTime: 2001-09-22 11:45:50 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!sn-xit-01!sn-post-02!sn-post-01!supernews.com!corp.supernews.com!not-for-mail
From: "Jon A. Cruz" <joncruz@geocities.com>
Newsgroups: be.comp.programming,comp.lang.java.gui,comp.lang.java.help,comp.lang.java.programmer
Subject: Re: Question: drawing on JPanel II (How to get the lower right corner)
Followup-To: comp.lang.java.gui
Date: Sat, 22 Sep 2001 11:43:51 -0700
Organization: Posted via Supernews, http://www.supernews.com
Message-ID: <3BACDBE7.A255632F@geocities.com>
X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.4.3-12 i686)
X-Accept-Language: en
MIME-Version: 1.0
References: <CN3r7.65846$6x5.14500406@afrodite.telenet-ops.be>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Complaints-To: newsabuse@supernews.com
Lines: 43