Scala - the menu bar appears only when updating the contents of the window

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

When the window is resized, a menu appears.

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

Any idea why this is so and how I can prevent this?

+3
source share
1 answer

Try changing the order of the operators. For instance. bringing visible = trueto the end of the definition frame.

Another thing is to call the method packafter creation frame.

+6
source

Source: https://habr.com/ru/post/1756854/


All Articles