title: Scala Swing: How to pan an image using your mouse?
body: <p>I have been trying to replicate some <a href="https://stackoverflow.com/questions/13341857/how-to-pan-an-image-using-your-mouse-in-java-swing">Java Swing</a> work in Scala. In the code below <code>this</code> extends Scala Swings <code>ScrollPane</code>. </p>
  
  <pre><code>myPanel.reactions +={
      case MouseDragged(_,x,_) =&gt; {
        //val viewport = this.viewportView.get.asInstanceOf[JViewport]
        val viewport = this.contents.head.self.asInstanceOf[JComponent].getParent.asInstanceOf[JViewport]
        println(viewport.getViewPosition)
        val vp = viewport.getViewPosition
        var cp = x.getLocation
        vp.translate(point.x-cp.x,point.y-cp.y)
        //newLoc = new Point(vp.getX)
        val jComp = contents.head.asInstanceOf[JComponent]
        jComp.scrollRectToVisible(new Rectangle(vp,viewport.getSize: Dimension))
      }
      case MousePressed(_,x,_,_,_) =&gt; point = x.getLocation
      case MouseClicked(_,_,_,_,_) =&gt; println("click")
  }
  </code></pre>
  
  <p>I can't see how to get access to the <code>Viewport</code> object as in the Java code in the related question. How should this be implemented in Scala Swing?</p>