Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala - menu bar only appears when window contents revalidated

Tags:

scala

swing

menu

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 http://grab.by/grabs/4a0ffda4603149a4680415447c684129.png

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

alt text http://grab.by/grabs/cef34bf57327edf6d47f9a0e14902285.png

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

like image 269
I82Much Avatar asked Dec 18 '25 08:12

I82Much


1 Answers

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.

like image 153
michael.kebe Avatar answered Dec 20 '25 22:12

michael.kebe