带动作的Scala Swing按钮
我在视图中创建了一个带有标题和图标的按钮带动作的Scala Swing按钮,swing,scala,button,icons,action,Swing,Scala,Button,Icons,Action,我在视图中创建了一个带有标题和图标的按钮 object playButton extends Button("play") { icon = new ImageIcon(getClass.getResource("/Play.gif")) verticalTextPosition = Alignment.Bottom horizontalTextPosition = Alignment.Center } 现在我想在控制器中添加一些操作 view.playButton.action
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
我做错了什么?文档中的操作具有图标字段的设置器:。查看
在伴随的对象中
:
def apply(title: String)(body: =>Unit) = new Action(title) {
def apply() { body }
}
换句话说,为了方便您,他们使用块(您放置图标=…
)并将其作为操作的事件处理程序
您实际上想要做的是子类:
new Action("Hello") {
icon = ...
def apply() = ...
}
这似乎没有记录在案。查看
在伴随的对象中
:
def apply(title: String)(body: =>Unit) = new Action(title) {
def apply() { body }
}
换句话说,为了方便您,他们使用块(您放置图标=…
)并将其作为操作的事件处理程序
您实际上想要做的是子类:
new Action("Hello") {
icon = ...
def apply() = ...
}
这似乎没有记录在案