Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scala.swing.Menu contents field permanently empty #130

Open
scabug opened this issue Sep 17, 2009 · 2 comments
Open

scala.swing.Menu contents field permanently empty #130

scabug opened this issue Sep 17, 2009 · 2 comments
Assignees

Comments

@scabug
Copy link

scabug commented Sep 17, 2009

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)
@scabug
Copy link
Author

scabug commented Sep 17, 2009

Imported From: https://issues.scala-lang.org/browse/SI-2362?orig=1
Reporter: Tom Coxon (tomc)

@scabug
Copy link
Author

scabug commented Aug 11, 2013

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())
  
}

@scabug scabug closed this as completed Jul 17, 2015
@SethTisue SethTisue transferred this issue from scala/bug Nov 19, 2020
@scala scala deleted a comment from scabug Nov 19, 2020
@SethTisue SethTisue reopened this Nov 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants