Article View: borland.public.jbuilder.java.swing
Article #9960Re: JButton borders
From: George Lefter
Date: Sun, 19 Dec 1999 00:00
Date: Sun, 19 Dec 1999 00:00
56 lines
2846 bytes
2846 bytes
hello, John
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. like this:
for(int i=10; i<60;i+=10)
g.drawRect( X0-i, Y0-i, width+2*i, height+2*i);
but they get misplaced, so i broke down the problem to trying to draw a
rectangle
that correctly surrounds my button. i just cant make the rectangle have
the same symmetry center as the button.
about the super.paint() call, it is in my code, i just forgot to write
it in the email.
John P. McGrath wrote:
>
> On Sun, 19 Dec 1999 06:46:46 +0200, George Lefter wrote:
>
> > hello. how can i draw a rectangle exactly on a button's border/edges?
> > the code below draws the rectangle above and in the left of the button..
> > how should i change the line g.drawRect(..) ?
>
> Instead of trying to draw this yourself, you could set the border
> property for the button. Use something like:
>
> button.setBorder( BorderFactory.createLineBorder( Color.black ) );
>
> If the button already has a border, and you want to create an additional
> one, then you could use a CompoundBorder, including the border that it
> has, plus the new one you want to add.
>
>
> A few notes on the above code:
>
> If you are going to write your own paint code for a Swing component, you
> usually should override paintComponent() instead of paint(). The paint()
> method calls paintComponent(), but it also handles painting the child
> components, and painting the borders. Note that whether it has any
> children is part of the implementation of the component, so you probably
> should not assume it does not. Even if the current implementation does
> not, a future one may.
>
> Also, for both paint() and paintComponent(), you usually should call the
> superclass implementation first, unless you want to eliminate some of its
> behavior. If you do not, you may be eliminating some behavior that you
> want. For instance, the superclass handles painting the component
> background. For example:
>
> public void paintComponent( Graphics g ) {
> super.paintComponent( g );
> // do additional stuff.
> }
Technical Details
Message-ID:
<385CE869.F7778E6D@void.art.ro>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<385C6336.DFBE63B1@void.art.ro> <MPG.12c64d5810352fee989708@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,c49df965457840ee X-Google-Attributes: gid111d45,public From: George Lefter <giku@void.art.ro> Subject: Re: JButton borders Date: 1999/12/19 Message-ID: <385CE869.F7778E6D@void.art.ro> X-Deja-AN: 562634454 Content-Transfer-Encoding: 7bit References: <385C6336.DFBE63B1@void.art.ro> <MPG.12c64d5810352fee989708@forums.borland.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: Another Netscape Collabra Server User Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing