gpt4 book ai didi

events - Scala Swing 事件框架 - 在哪里添加 react 器?

转载 作者:行者123 更新时间:2023-12-02 00:10:46 25 4
gpt4 key购买 nike

我试图捕捉鼠标点击,即使是在Table上(这应该会导致显示弹出窗口)。该表位于 ScrollPane 内,而 ScrollPane 又位于 Panel 内。我已经为所有类添加了 react ,但我似乎永远无法真正捕获点击事件!

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)
}
}

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

最佳答案

好的 - 你必须正确的事情:

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)
}
}
}

关于events - Scala Swing 事件框架 - 在哪里添加 react 器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/938437/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com