-
Bug
-
Resolution: Fixed
-
P2
-
1.2.0
-
swing1.0fcs
-
unknown
-
solaris_2.5.1
From: Hans Muller <hmuller@Eng>
To: ###@###.###
Cc: ###@###.###
Subject: JComponent's getSize, getBounds, etc.
Date: Mon, 2 Feb 1998 08:04:00 -0800
Good point, we'll try and get that in for Swing1.0.
- Hans
Rich Kadel writes:
> In your new versions of getSize, etc. that take an object as a parameter
> (so it doesn't have to allocate one), I recommend that you check for
> null, then allocate one and return it only if null. This would be much
> simpler and safer to use. For instance:
>
> public class SomeClass extends JComponent {
> private Dimension size;
>
> public void doSomething() {
> size = getSize(size);
> // size is definitely valid now, and the newly allocated pointer
> can now be reused
> }
> }
>
> Of course, this only works if getSize is implemented as:
>
> public Dimension getSize(Dimension rv) {
> if (rv == null) rv = new Dimension();
> rv.setSize(_bounds.width, _bounds.height);
> return rv;
> }
>
> This adds one line of code and doesn't break the existing
> implementation.
>
> Thanks,
> Rich
> --
>
> |-------------------------------------------------------------------
> | Rich Kadel
> | DTAI, Incorporated - http://www.dtai.com
> | mailto:###@###.###
> | snailto: 3900 Harney Street, San Diego, CA 92110
> | (619) 542-1700 - (FAX) 542-8675
> |-------------------------------------------------------------------
> | Java, C++, HTML, CGI, Windows, Unix, DBMS, 3D, ...
> |-------------------------------------------------------------------
>
>
>
To: ###@###.###
Cc: ###@###.###
Subject: JComponent's getSize, getBounds, etc.
Date: Mon, 2 Feb 1998 08:04:00 -0800
Good point, we'll try and get that in for Swing1.0.
- Hans
Rich Kadel writes:
> In your new versions of getSize, etc. that take an object as a parameter
> (so it doesn't have to allocate one), I recommend that you check for
> null, then allocate one and return it only if null. This would be much
> simpler and safer to use. For instance:
>
> public class SomeClass extends JComponent {
> private Dimension size;
>
> public void doSomething() {
> size = getSize(size);
> // size is definitely valid now, and the newly allocated pointer
> can now be reused
> }
> }
>
> Of course, this only works if getSize is implemented as:
>
> public Dimension getSize(Dimension rv) {
> if (rv == null) rv = new Dimension();
> rv.setSize(_bounds.width, _bounds.height);
> return rv;
> }
>
> This adds one line of code and doesn't break the existing
> implementation.
>
> Thanks,
> Rich
> --
>
> |-------------------------------------------------------------------
> | Rich Kadel
> | DTAI, Incorporated - http://www.dtai.com
> | mailto:###@###.###
> | snailto: 3900 Harney Street, San Diego, CA 92110
> | (619) 542-1700 - (FAX) 542-8675
> |-------------------------------------------------------------------
> | Java, C++, HTML, CGI, Windows, Unix, DBMS, 3D, ...
> |-------------------------------------------------------------------
>
>
>