I have a collection of ComboBox declared as below.
val cmbAll = for (i <- 0 to 4) yield new ComboBox(List("---", "Single", "Double"))
And I try to listen to one of it via
listenTo(cmbAll(0).selection)
However, I can't actually perform the reactions.
reactions += {
case SelectionChanged(`cmbAll(0)`) => /** action here **/
}
All these are placed in a TabbedPane. I guess this is not the problem. So how can I listen to individual components inside of the collection?
Edited
This is a more complete code that I am trying in Eclipse.
import scala.swing._
import scala.swing.event._
object CMBTest extends SimpleSwingApplication {
lazy val ui = new TabbedPane {
import TabbedPane._
val cmbCategory = for (i <- 0 to 4) yield new ComboBox(List("---", "Single", "Double"))
val cmbTab = new GridBagPanel {
import GridBagPanel._
val c = new Constraints
c.insets = new Insets(5, 5, 5, 5)
for (i <- 0 to 4) {
c.gridx = 0
c.gridy = i
layout(cmbCategory(i)) = c
}
}
pages += new Page("CMBTest", cmbTab)
list开发者_Python百科enTo(cmbCategory(0))
reactions += {
case SelectionChanged(`cmbCategory(0)`) => {
println("This is cmbCategory(0) calling")
}
}
}
def top = new MainFrame {
title = "ComboBox Array Test"
contents = ui
}
}
That error message that I am having is in the reactions part and it states that "not found: value cmbCategory(0)".
I don't think anything other than a stable identifier is allowed inside ` in pattern matches. In your case, you are implicitly calling the apply
method by doing (0)
.
You may try instead this:
val category = cmbCategory(0)
case SelectionChanged(`category`) => {
println("This is cmbCategory(0) calling")
精彩评论