MouseWheelEvent Horizontal and Vertical

edited October 2013 in How To...

Hello, I want receive the horizontal and vertical wheel event, with mouseWheel(MouseEvent event) it's easy to catch the both but you don't know who is this one. So I search on Stckoverflow and I find this path I try to adapt but it's to hard for me. If anybody have an idea it's welcome.

class MyJScrollPane extends JScrollPane 
{
  public MyJScrollPane(Component component)
  {
    super(component);
    final JScrollBar horizontalScrollBar = getHorizontalScrollBar();
    final JScrollBar verticalScrollBar = getVerticalScrollBar();
    setWheelScrollingEnabled(false);
    addMouseWheelListener(new MouseAdapter()
    {
      public void mouseWheelMoved(MouseWheelEvent evt)
      {
        println("je suis là!") ;
        if (evt.getWheelRotation() >= 1)//mouse wheel was rotated down/ towards the user
        {
          int iScrollAmount = evt.getScrollAmount();
          int iNewValue = horizontalScrollBar.getValue() + horizontalScrollBar.getBlockIncrement() * iScrollAmount * Math.abs(evt.getWheelRotation());
          if (iNewValue <= horizontalScrollBar.getMaximum())
          {
              horizontalScrollBar.setValue(iNewValue);
          }
        }
        else if (evt.getWheelRotation() <= -1)//mouse wheel was rotated up/away from the user
        {
          int iScrollAmount = evt.getScrollAmount();
          int iNewValue = horizontalScrollBar.getValue() - horizontalScrollBar.getBlockIncrement() * iScrollAmount * Math.abs(evt.getWheelRotation());
          if (iNewValue >= 0)
          {
              horizontalScrollBar.setValue(iNewValue);
          }
        }
      }
    });
  }
}

Answers

  • "horizontal and vertical wheel event"
    You have a special mouse with 2D wheel movement?

    The code you show doesn't handle this, it just handle forward / backward rotation. There is a reference to a vertical scrollbar but apparently it isn't handled there.

  • edited October 2013

    yes with horizontal move and vertical move. I can use this option on the window with horizontal and vertical scrolling, or in Photoshop to move the picture to the top, left, right or left. It's nice if we can use that in Processing. But I don't find a way to code that in Processing, and in Java often it's to complex for me.

    about the code, the code talk about horizontalScroolBar too ?

  • It is about only one scrollbar, apparently it cannot manage both of them. I don't know if Java has standard support for this unusual hardware. Perhaps it needs the support of some specific library (we have to find one to use a graphics tablet, for example).

  • edited November 2013

    Is not really not unusual, all the "magic" mouse have this function for the horizontal scroll. What do you mean when you talk about specific library like the graphic tablet ? A library for Java or for Processing ?

    I find a post about that, but my english is not really fluid to understand exactly the "sens" http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6440198

  • The graphics tablet was just an example of device not "standard" (unlike regular mouse and keyboard) that need special support (library, generally taping into some native code DLL/shared library) to be used on Java.

    Personally, I use computers (professionally and personally) for more than 30 years and still hadn't such mouse in hand, that's what I call "unusual"... :-D

    It is relative: having two mouse buttons was unusual on Mac computers for a long time! Regular mouse wheels are now on almost every mouse but where rare at first. Etc.

  • So we're in progress ! You think there is a solution for this unusual mouse :) ?

  • If there is one, Google (or Bing or whatever you like) might find it... Don't search for Processing, search for Java.

  • allright captain

Sign In or Register to comment.