Scollbar

How to use the ScrollBar on a Applet?
How to use the ScrollBar on a Panel?
hongvu547Asked:
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.
0
heyhey_Commented:
it depends on why you want to use it :)
simple add it to the container (panel / applet) add AdjustmentListener and track all the events.
0
SmillyCommented:
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);
      add(hSb);
      add(vSb);
      hSb.setVisible(true);
      vSb.setVisible(true);
      hSb.setBackground(new Color(198,195,198));
      vSb.setBackground(new Color(198,195,198));
      hSb.setValues(0,1,0,100);
      vSb.setValues(0,1,0,100);
        vSb.setBounds(1,getSize().height-16,getSize().width-15,15);                  
        hSb.setBounds(getSize().width-16,1,15,getSize().height-15);                  
    }


      public boolean handleEvent(Event e)
      {
            switch (e.id) {
              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 (e.target == hSb) {
                                    xpos = hSb.getValue();
                                    return true;
                              }      
                              else if (e.target == vSb) {
                                    ypos = vSb.getValue();
                                    return true;
                              }      
        }
        return super.handleEvent(e);
      }
}


                  

0

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
SmillyCommented:
I forgot remove mouselistener, it isn't part of your task..
So remove mouselistener.....

Smilly
0
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
Java

From novice to tech pro — start learning today.