Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Scollbar

Posted on 1999-07-18
4
Medium Priority
?
183 Views
Last Modified: 2010-05-18
How to use the ScrollBar on a Applet?
How to use the ScrollBar on a Panel?
0
Comment
Question by:hongvu547
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 

Author Comment

by:hongvu547
ID: 1246403
Edited text of question.
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 1246404
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
 
LVL 1

Accepted Solution

by:
Smilly earned 400 total points
ID: 1246405
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
 
LVL 1

Expert Comment

by:Smilly
ID: 1246406
I forgot remove mouselistener, it isn't part of your task..
So remove mouselistener.....

Smilly
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question