scala-swing
scala-swing copied to clipboard
scala.swing.Menu contents field permanently empty
The following code prints 0, the length of the menu's contents field, but it should be 1. It is also impossible to access the elements in contents.
It is interesting to note, however, that if the menu was to be shown, it would indeed have the item "foobar" in it.
import scala.swing._
val menu = new Menu("File") {
contents += new MenuItem("foobar")
}
println(menu.contents.length)
Imported From: https://issues.scala-lang.org/browse/SI-2362?orig=1 Reporter: Tom Coxon (tomc)
Kent Tong (freemant) said: Yeah, it is definitely incorrect. The core of the issue may be that JMenu is not really a JComponent container but Scala treats it so. To work around it, use the peer:
import scala.swing.Menu
import scala.swing.MenuItem
object Test extends App {
val menu = new Menu("m1") {
contents += new MenuItem("a")
}
println(menu.contents.size)
println(menu.peer.getItemCount())
}