Scala Swing事件框架 - 我在哪里添加反应堆? [英] Scala Swing event framework - where do I add my reactors?
本文介绍了Scala Swing事件框架 - 我在哪里添加反应堆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图抓住鼠标点击,即使在表
(应该会弹出一个弹出窗口)。该表位于 ScrollPane
之内,而另一个则在面板
之内。我已经对所有的课程添加了反应,但我似乎无法真正得到一个点击事件被抓住!
I'm trying to catch a mouse-click even on a Table
(which should cause a popup to be shown). The table is inside a ScrollPane
which is (in turn) inside a Panel
. I have added reactions to all the classes, but I can never seem to actually get a click event to be caught!
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)
}
}
无论我点击什么,都没有打印出来。我做错了什么?
No matter where I click, nothing gets printed. What am I doing wrong?
推荐答案
OK - 你必须听正确的事情: / p>
OK - You have to listen to the correct thing:
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)
}
}
}
这篇关于Scala Swing事件框架 - 我在哪里添加反应堆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文