我正在尝试实现一个简单的应用程序,在该应用程序中我可以在 Textfield 中编写一个项目,然后输入一个按钮,该按钮反过来通过将该项目插入组合框中来做出反应。
但是,我面临一个问题,即 scala 组合框摆动不可变(我猜)?
有没有办法使用 scala swing 使组合可变?
import scala.swing._
import scala.swing.event._
import scala.swing.BorderPanel.Position._
object ReactiveSwingApp extends SimpleSwingApplication {
def top = new MainFrame {
title = "Reactive Swing App"
val button = new Button {
text = "Add item"
}
var textfield = new TextField {
text = "Hello from a TextField"
}
var items = List("Item 1","Item 2","Item 3","Item 4")
val combo = new ComboBox(items)
contents = new BorderPanel {
layout(new BoxPanel(Orientation.Vertical) {
contents += textfield
contents += button
contents += combo
border = Swing.EmptyBorder(30, 30, 10, 30)
}) = BorderPanel.Center
}
listenTo(button, textfield)
reactions += {
case ButtonClicked(button) =>
// var items1 = textfield.text :: items <- how can a read Item be inserted
}
}
}