Article View: borland.public.jbuilder.java.swing
Article #9878Re: JButton borders
From: John P. McGrath
Date: Thu, 23 Dec 1999 00:00
Date: Thu, 23 Dec 1999 00:00
37 lines
2072 bytes
2072 bytes
On Sun, 19 Dec 1999 16:15:05 +0200, George Lefter wrote:
> thank you for your help. your ideea with creating a border
> is good, but what i actually wanted to do is draw about
> five "concentric" rectangles around the button.
You should be able to do that using a Border as well, just a slightly
more complicated one. You can use a CompoundBorder to combine two
borders. By doing this multiple times, you can create almost any effect
you want. Note that you can re-use the Border objects -- the same
LineBorder is used each time.
Border line = BorderFactory.createLineBorder(
Color.black, lineWidth );
Border space = BorderFactory.createEmptyBorder(
spaceWidth, spaceWidth, spaceWidth, spaceWidth );
Border border = line;
for ( int i = 1; i < count; ++ i ) {
border = new CompoundBorder( border, space );
border = new CompoundBorder( border, line );
}
component.setBorder( border );
This does use a number of Border objects, but it is really not that
expensive, and you don't have to write any painting code.
If you really want to do your own drawing code, then you could create
your own Border class, say a MultiLineBorder. You only need to implement
three methods for the Border interface. Two of them should be trivial,
and the third would just entail the paint code that you are writing.
Then you would be able to easily re-use your drawing code with any
component.
--
John P. McGrath
<JPMcGrath@fast.net>
<jpm@nscs.fast.net>
Technical Details
Message-ID:
<MPG.12cb8e471f081ab198970f@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<385C6336.DFBE63B1@void.art.ro> <MPG.12c64d5810352fee989708@forums.borland.com> <385CE869.F7778E6D@void.art.ro>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,c49df965457840ee X-Google-Attributes: gid111d45,public From: John P. McGrath <JPMcGrath@fast.net> Subject: Re: JButton borders Date: 1999/12/23 Message-ID: <MPG.12cb8e471f081ab198970f@forums.borland.com> X-Deja-AN: 564096422 References: <385C6336.DFBE63B1@void.art.ro> <MPG.12c64d5810352fee989708@forums.borland.com> <385CE869.F7778E6D@void.art.ro> Organization: Another Netscape Collabra Server User Newsgroups: borland.public.jbuilder.java.swing