0

I have been trying to replicate some Java Swing work in Scala. In the code below this extends Scala Swings ScrollPane.

myPanel.reactions +={
    case MouseDragged(_,x,_) => {
      //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,_,_,_) => point = x.getLocation
    case MouseClicked(_,_,_,_,_) => println("click")
}

I can't see how to get access to the Viewport object as in the Java code in the related question. How should this be implemented in Scala Swing?

Community
  • 1
  • 1
Codey McCodeface
  • 2,988
  • 6
  • 30
  • 55

1 Answers1

0
  myPanel.reactions +={
    case MouseDragged(myPanel,x,_) => {
      val cp = x.getLocation
      this.horizontalScrollBar.value += point.x-cp.x
      this.verticalScrollBar.value += point.y-cp.y
      point = cp
    }
    case MousePressed(_,x,_,_,_) => point = x.getLocation
  }
Codey McCodeface
  • 2,988
  • 6
  • 30
  • 55