Scala Swing事件框架 - 我在哪里添加我的反应器?

时间:2009-06-02 08:10:31

标签: events scala scala-swing

即使在Table上也试图捕捉鼠标点击(这会导致弹出窗口显示)。该表位于ScrollPane内,Panel位于class MyPanel extends GridBagPanel { val gbc = new GridBagContraints( ... ) add(new ScrollPane { reactions += { case MouseClicked(src, point, mod, clicks, pops) => println("Scroll pops: " + pops) } viewportView = new Table { reactions += { case MouseClicked(src, point, mod, clicks, pops) => println("Table pops: " + pops) } ... } }, gbc) reactions += { case MouseClicked(src, point, mod, clicks, pops) => println("Panel pops: " + pops) } } 内。我已经添加了对所有类的反应,但我似乎永远不会真正得到一个点击事件被捕获!

{{1}}

无论我点击哪里,都不会打印任何内容。我做错了什么?

1 个答案:

答案 0 :(得分:5)

好的 - 您必须倾听以正确的事情:

class MyPanel extends GridBagPanel {
  val gbc = new GridBagContraints( ... )

  val table = new Table { ... }

  add(new ScrollPane {

    viewportView = table
  }

  }, gbc)

  listenTo(table.Mouse.clicks) //THIS LINE IS IMPORTANT :-)

  reactions += {
    case MouseClicked(`table`, point, mod, clicks, pops) =>
      println("Panel pops: " + pops)
    } 
  }
}