views:

39

answers:

1
import scala.swing._
import swing.event.{WindowClosing}
import java.awt.Dimension
object MenuBarTest {
  def main(args:Array[String]) {


    val frame = new Frame() {
      visible=true
      contents = new Panel() {
        preferredSize = new Dimension(600,400)
      }
      title = "Test"
      reactions += {
        case WindowClosing(e) => System.exit(0)
      }
      menuBar = new MenuBar {   
        contents += new Menu("A Menu") {      
          contents += new MenuItem("An item")      
          contents += new MenuItem(Action("Action item") { println(title) })       
          contents += new Separator        
          contents += new CheckMenuItem("Check me")
        }
      }
    }
  }
}

alt text

The instant I resize the window, the menu pops in.

alt text

Any idea why this is and how I can prevent this from happening?

+5  A: 

Try changing the order of the statements. E.g. bringing visible = true to the end of the frame definition.

Another thing would be to call the pack method after creating frame.

michael.kebe
I tried to move visible = true to the end and it works. Why? This is natural, if you make the frame visible before the menu is created it will not show until it is re-rendered.
olle kullberg
2 thumbs up. Worked perfectly.
I82Much