0
我一直在試圖複製斯卡拉的一些Java Swing工作。在下面的代碼this
延伸斯卡拉鞦韆ScrollPane
。Scala Swing:如何使用鼠標平移圖像?
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")
}
我看不出如何獲得訪問Viewport
對象中的相關問題Java代碼。 Scala Swing應該如何實現?