Scala Swing - 带操作的按钮
我在视图中创建了一个带有标题和图标的按钮。
object playButton extends Button("play") {
icon = new ImageIcon(getClass.getResource("/Play.gif"))
verticalTextPosition = Alignment.Bottom
horizontalTextPosition = Alignment.Center
}
现在我想在控制器中添加一些操作。
view.playButton.action = Action(view.playButton.text) {
//...
}
问题是,此操作会覆盖按钮图标。所以...我尝试过:
view.playButton.action = Action(view.playButton.text) {
icon = view.playButton.icon
}
编译器说:
[info] Compiling main sources...
[error] .../Controller.scala:11: not found: value icon
[error] icon = view.playButton.icon
[error] ^
[error] one error found
我做错了什么?文档中的操作具有图标字段的设置器: http://www .scala-lang.org/api/current/scala/swing/Action.html。
I've created a button with title and icon in my view.
object playButton extends Button("play") {
icon = new ImageIcon(getClass.getResource("/Play.gif"))
verticalTextPosition = Alignment.Bottom
horizontalTextPosition = Alignment.Center
}
Now I want to add it some action in the controller.
view.playButton.action = Action(view.playButton.text) {
//...
}
The problem is, that this action overrides buttons icon. So... i tried:
view.playButton.action = Action(view.playButton.text) {
icon = view.playButton.icon
}
Compiler says:
[info] Compiling main sources...
[error] .../Controller.scala:11: not found: value icon
[error] icon = view.playButton.icon
[error] ^
[error] one error found
What am I doing wrong? Action in documentation has this setter for icon field: http://www.scala-lang.org/api/current/scala/swing/Action.html.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看 source for scala.swing.Action
在配套的
object
中:换句话说,为了方便您,它们采用了块(您放置的位置)
icon = ...
) 并将其作为该操作的事件处理程序。您真正想做的是子类:
这似乎没有记录。
Look at the source for scala.swing.Action
In the companion
object
:In other words, as a convenience to you, they take the block (where you put
icon = ...
) and make that be the event handler for the Action.What you actually want to do is subclass:
This does not appear to be documented.