Article View: borland.public.jbuilder.java.swing
Article #11277Re: JScrollPane does not work !!!
From: Paul Furbacher
Date: Tue, 15 Jun 1999 00:00
Date: Tue, 15 Jun 1999 00:00
37 lines
1768 bytes
1768 bytes
Qiang Song wrote:
>
> I solved this problem by overriding the getPreferredSize function.
>
> public Dimension getPreferredSize(){
> return new Dimension(img.getWidth(null), img.getHeight(null));
> }
>
> This can not be solved by setting the canvas size!
The reason you have to override this method is that
Canvas.getPreferredSize() really has no way of knowing
that the "img" instance variable of your subclass "myCanvas"
even exists.
Wihelmsen's suggestion that you base your subclass on
JComponent would obviate the need to override
"getPreferredSize()" if you invoke "this.setPreferredSize()"
immediately after loading your image in the constructor
of your subclass.
public myJCanvas(){
//you may change image to your own
img = Toolkit.getDefaultToolkit().getImage("AboutSwing.gif");
// add this ...
this.setPreferredSize(new Dimension(img.getWidth(null), img.getHeight(null)));
}
In addition, you may want to make sure that any
view/component you place into the JViewport
implements the Scrollable interface. This will
give your object control over the scrolling units.
Paul Furbacher
Technical Details
Message-ID:
<376689AB.487D5C00@bilbo.bio.purdue.edu>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<37645300.7636ED33@kla-tencor.com> <37653922.8BB5410C@kla-tencor.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,8e0dc61fd8ca804f X-Google-Attributes: gid111d45,public From: Paul Furbacher <pf@bilbo.bio.purdue.edu> Subject: Re: JScrollPane does not work !!! Date: 1999/06/15 Message-ID: <376689AB.487D5C00@bilbo.bio.purdue.edu> X-Deja-AN: 489918122 Content-Transfer-Encoding: 7bit References: <37645300.7636ED33@kla-tencor.com> <37653922.8BB5410C@kla-tencor.com> Content-Type: text/plain; charset=us-ascii Organization: Reverse Alchemy, Inc. Mime-Version: 1.0 Reply-To: pf@bilbo.bio.purdue.edu Newsgroups: borland.public.jbuilder.java.swing