[5682] in java-interest
Re: ScrollBars !
daemon@ATHENA.MIT.EDU (Greg Ewing)
Thu Feb 22 09:04:40 1996
Date: Thu, 22 Feb 1996 15:52:14 +1100
From: grege@optimation.com.au (Greg Ewing)
To: java-interest@java.sun.com
Cc: kovan@ecf.toronto.edu
> From NewsGroup_comp-lang-java Thu Feb 22 08:26 EST 1996
> From: NewsGroup_comp-lang-java
> >From: kovan@ecf.toronto.edu (KOVAN GERRY)
> Subject: ScrollBars !
> X-Nntp-Posting-Host: spark18.ecf
> Date: Wed, 21 Feb 1996 01:41:46 GMT
>
> I am trying to implement a scrollbar. The vertical and horizontal
> scrollbars appear on the screen and I can move the position of the
> scrollbars. The problem is the position of the object (in this case
> a rectangle) does not change. Does anyone know what is wrong.
>
> Can you please reply to me as well as the newsgroup. My email is:
>
> kovan@skule.ecf.toronto.edu
>
>
> The following is the code that is not working properly:
>
> import java.awt.*;
> import java.applet.Applet;
>
> class MyPanel extends Panel
> {
> MyPanel()
> {
> }
>
> public void paint(Graphics g)
> {
> g.setColor(Color.blue);
> g.drawRect(480,100,50,50);
> g.fillRect(480,100,50,50);
> g.setColor(Color.red);
> g.drawRect(480,100,50,20);
> g.fillRect(480,100,50,20);
> g.clipRect(480,100,50,20);
> g.setColor(Color.black);
> g.drawString("Lanscpae Program",480,110);
> }
>
> }
>
> public class test extends Applet
> {
>
> MyPanel MyNewPanel = new MyPanel();
>
> public void init()
> {
> boolean proceed;
> resize(500,300);
> setLayout(new BorderLayout());
> add("Center",MyNewPanel);
> add( "East", new Scrollbar(Scrollbar.VERTICAL,0,300,-200,500) );
> add( "South", new Scrollbar(Scrollbar.HORIZONTAL,0,500,-200,700) );
> }
>
> }
> --
>
>
> Gerry Kovan Email address: kovan@skule.ecf.toronto.edu
> Computer Engineering
>
Gerry,
Just adding scrollbars to a Panel is not enough. You have to add the
functionality to respond to the scrollbar position. This is not exactly a
trivial task.
Check out some sites where scrolling panels live.
Here are two recent postings that might help:
--------------------------------------------------------------------------------
SOURCE 1.
From NewsGroup_comp-lang-java Sat Jan 6 22:12 EST 1996
From: NewsGroup_comp-lang-java
>From: lieske@princeton.edu (Jay Lieske Jr.)
Subject: I am the Scroller, goo-goo-ga-choo
Date: Fri, 05 Jan 1996 16:19:46 -0500
Nntp-Posting-Host: guston.princeton.edu
One of the pieces missing from Java's AWT has been an easy-to-use tool for
scrolling Components using scrollbars. (I'm not speaking of the
animations where images move across the screen, but something that the
user actually controls.)
I have written a (hopefully) general-purpose Scroller component for Java
beta 1.0 AWT. I've seen it work under appletviewer for Solaris and
Netscape 2beta for Unix.
The Scroller takes an arbitrary AWT Component and displays it in a pane
controlled by scrollbars. The scrolled Component functions perfectly
normally -- it gets all the standard paint(), handleEvent(), etc. calls.
The Component can change its size and the scrollbars keep track of the
changes.
You can get the Scroller from
http://www.princeton.edu/~lieske/java/scroller/
I have documentation there on how to use the Scroller and how it works.
Please email me with comments. As of 21 Dec. 1995, I've only used it on
one project, a prototype Princeton University campus map,
http://www.princeton.edu/~scimath/campusmap.html
and I mainly used it with the beta1 JDK on Solaris 2.4 and Netscape
2.0beta2 on Solaris 2.4 and Irix 5.2.
How to use:
Create an instance of Scroller, pass it a Component to control, and add
the Scroller to your Panel, Applet, etc.:
myComponent = new ...;
add( new Scroller( myComponent));
The Scroller, with its own scrollbars, gets added to your Container, but
unless you want to control the scrolled region programmatically, you
needn't keep a reference to it.
How it works:
Scroller is a Panel that holds a ScrollerPanel and two Scrollbars. The
Components that are scrolled by the Scroller are held inside the
ScrollerPanel, which is a private class. The ScrollerPanel handles the
clipping and translating of paint and event coordinates; the Scroller
manages the scrollbars.
Scrolling is accomplished by move()ing the Component within the
ScrollerPanel. The Scroller and ScrollerPanel share information on the
area of the scrolled Components to keep the scrollbars in sync. The
ScrollerPanel's PanelPeer handles the clipping and translating of
coordinates for the scrolled Components.
Bugs:
There is a bad flickering problem during scrolling. Even paint()ing only
an Image flickers badly. I assume that this is because the move() which
performs the scroll paint()s the contained Components, instead of invoking
update(). I believe that a java.awt.peer.PanelPeer controls this process,
but I can't change the Peer's operation.
Enjoy,
--jay
___________________________________________________
Jay Lieske Jr. <lieske@princeton.edu>
Science and Engineering Specialist (609)258-6050
Computer and Information Technology fax 258-3943
Princeton University, Princeton, NJ 08544
http://www.princeton.edu/~lieske/
--------------------------------------------------------------------------------
SOURCE 2.
From NewsGroup_comp-lang-java Mon Feb 5 22:13 EST 1996
From: NewsGroup_comp-lang-java
>From: Kwin Kramer <khkramer@bitwise.net>
Subject: Re: Handling event on Scrollbar
Date: Sun, 04 Feb 1996 22:05:42 -0500
Nntp-Posting-Host: khkramer.student.harvard.edu
Mime-Version: 1.0
Content-Transfer-Encoding: 7bit
To: Ken Koellner <koellnk@rx>
Ken Koellner wrote:
>
> I can put a scrollbar on my applet and look at the current value. I'd
> like to set up my applet so a method is called when teh scrollbar
> value changes. I've looked at the online documentation on event
> handling but haven't figured out a way to do what I want.
>
> Anyone have an idea as to how to set up a scrollbar so it does the normal
> scrollbar thing and then a call a user-specified method?
>
> --
> Ken Koellner, Software Architect
> Houghton Mifflin Company Email: kvk@hmco.com
> Boston, MA or: koellnk@hmco.com
> http://www.hmco.com/ Notes: Ken_Koellner@hmco.com
Hi,
You can subclass the scrollbar and set up a handleEvent method. Check
out jesse's ScrollPanel class for an example of this:
http://www.cs.princeton.edu/~jhammons/java/awt/ScrollPanel/ScrollPanel.java
One thing that is pretty much essential in learning how to really use
the awt components is to write dummy subclasses of any component you are
planning to use, over-riding the handleEvent method to print out its
event id, target, string, modifiers -- whatever you might need. That way
you can tell what events are getting passed to you and how. Components
give you access only to the events they want to give you access to --
certain events are sucked up by the component peer itself and you never
get a crack at them.
Yours,
Kwin
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com