Article View: borland.public.jbuilder.java.api
Article #2744Re: Lines thicker than one pixel
From: John P. McGrath
Date: Sun, 14 May 2000 00:00
Date: Sun, 14 May 2000 00:00
29 lines
1480 bytes
1480 bytes
On Mon, 15 May 2000 00:57:29 +0200, David Br๏ฟฝnnvall wrote:
> is it possible to draw lines thicker than one pixel on a
> Graphics object?
It is not possible on any Graphics object directly, except by drawing
multiple lines or drawing a filled rectangle of the appropriate width.
But it is possible using Graphics2D, which is an extension of Graphics.
If you are running with JDK 1.2 or later, the Graphics object passed to
your paint method is actually a Graphics2D object.
Graphics2D provides a number of additional drawing attributes, one of
which is the "stroke". You can use it to specify the width of the line,
end caps, line joins and the dashing pattern.
Here is a simple example that draws a line that is 3 pixels wide from
[0,0] to [100,100]:
public void paint( Graphics graphics ) {
Graphics2D g = (Graphics2D) graphics;
g.setStroke( new BasicStroke( 3.0 ) );
g.drawLine( 0, 0, 100, 100 );
}
--
John P. McGrath
<JPMcGrath@fast.net>
<jpm@nscs.fast.net>
Technical Details
Message-ID:
<MPG.1389325db5b9d737989927@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<391f2d2a@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: 1089d0,cede310823e77c06,start X-Google-Attributes: gid1089d0,public From: John P. McGrath <JPMcGrath@fast.net> Subject: Re: Lines thicker than one pixel Date: 2000/05/14 Message-ID: <MPG.1389325db5b9d737989927@forums.borland.com> X-Deja-AN: 623455947 References: <391f2d2a@dnews> Organization: Another Netscape Collabra Server User Newsgroups: borland.public.jbuilder.java.api