How to use the ScrollBar on a Applet?
How to use the ScrollBar on a Panel?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hongvu547Author Commented:
Edited text of question.
it depends on why you want to use it :)
simple add it to the container (panel / applet) add AdjustmentListener and track all the events.
Hi hongvu547,
Here is a example on how to use a scrollbar, and it
works both in a Applet and a Panel.

Hope this help....

 import java.awt.Panel;
 import java.awt.Scrollbar;
 import java.awt.Event;
 import java.awt.event.*;
 import java.util.EventListener;

public class TstScroll extends Panel implements MouseListener {
    Scrollbar hSb, vSb;
    int xpos,ypos;
    public TstScroll()
      hSb = new Scrollbar(Scrollbar.HORIZONTAL);
      vSb = new Scrollbar(Scrollbar.VERTICAL);
      hSb.setBackground(new Color(198,195,198));
      vSb.setBackground(new Color(198,195,198));

      public boolean handleEvent(Event e)
            switch ( {
              case Event.SCROLL_LINE_UP:
              case Event.SCROLL_LINE_DOWN:
              case Event.SCROLL_PAGE_UP:
              case Event.SCROLL_PAGE_DOWN:
              case Event.SCROLL_ABSOLUTE:
                              if ( == hSb) {
                                    xpos = hSb.getValue();
                                    return true;
                              else if ( == vSb) {
                                    ypos = vSb.getValue();
                                    return true;
        return super.handleEvent(e);



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
I forgot remove mouselistener, it isn't part of your task..
So remove mouselistener.....

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.