Article View: borland.public.jbuilder.java.swing
Article #11350Re: JScrollPane does not work !!!
From: Qiang Song
Date: Mon, 14 Jun 1999 00:00
Date: Mon, 14 Jun 1999 00:00
46 lines
1695 bytes
1695 bytes
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!
Qiang Song wrote:
> Following is a very short testing code. There is no scrollbar with
> JScrollPane ! Same thing with ScrollPane. Help is wanted and
> aprreciated!
>
> import java.awt.*;
> import java.awt.image.*;
> import javax.swing.*;
>
> public class myFrame extends JFrame {
> JScrollPane scrollPane;
> myCanvas c;
> public myFrame(){
> c = new myCanvas();
> scrollPane = new JScrollPane(c);
> this.getContentPane().add(scrollPane);
> }
>
> public static void main(String args[]){
> myFrame f = new myFrame();
> f.setSize(200, 300);
> f.setVisible(true);
> }
> }
>
> class myCanvas extends Canvas{
> Image img;
>
> public myCanvas(){
> //you may change image to your own
> img = Toolkit.getDefaultToolkit().getImage("AboutSwing.gif");
> }
>
> public void paint(Graphics g){
> g.drawImage(img, 0, 0, this);
> }
> }
Technical Details
Message-ID:
<37653922.8BB5410C@kla-tencor.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<37645300.7636ED33@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: Qiang Song <qiang.song@kla-tencor.com> Subject: Re: JScrollPane does not work !!! Date: 1999/06/14 Message-ID: <37653922.8BB5410C@kla-tencor.com> X-Deja-AN: 489507212 Content-Transfer-Encoding: 7bit References: <37645300.7636ED33@kla-tencor.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