Disabling scroll bars/mouse wheel

Help
Hamilton
2008-05-26
2013-04-29
  • Hamilton

    Hamilton - 2008-05-26

    Hello! I'm working on a program that has a Browser (viewing a PDF) embedded in a JScrollPane, and we would like to use the JScrollPane's scroll bars rather than the Multivalent scroll bars. We have been able to hide the Multivalent scroll bars using Document.setScrollbarShowPolicy(), but when the mouse wheel is rotated it's still the Browser that does the scrolling; the MouseWheelEvent never reaches the JScrollPane.

    Does anyone know a way to turn Browser scrolling off altogether?

    Thanks.

     
    • Hamilton

      Hamilton - 2008-06-23

      Well, I finally figured it out. If anyone is interested, you need to create a behavior with an overriding eventBefore() method that does what you want with any MouseEvent.MOUSE_WHEEL events and then shortcircuits (returns true).

      Then add this behavior as an observer to the IScrollPane of your Browser's Root.
      Here's my Behavior code:

      public class BypassScrollPaneBehavior extends Behavior {
         
          // this gets used in place of a constructor
          public void restore(ESISNode n, Map attr, Layer layer){
              super.restore(n,attr,layer );
          }
         
          // This is the Multivalent equivalent of an EventListener
          public boolean eventBefore(AWTEvent e, Point rel, Node n) {
              if(super.eventBefore(e,rel,n))
                  return true;
              else{
                  boolean eat = false;
                  if(e instanceof MouseEvent){
                      MouseEvent me = (MouseEvent)e;
                      switch(me.getID()){
                      case MouseEvent.MOUSE_WHEEL:
                          // do stuff
                          eat = true;
                          break;
                      }
                  }
                  return eat;
              }
          }
      }

       

Log in to post a comment.