// // program illustrating simple use of GUI components // // another way to improve(?) layout -- add FlowPanels // import scala.swing._ import scala.swing.event._ // // label to display most recent action, with a function to update it // val LabelInitialSize = 100 // somewhat arbitrary initial size val textDisplay = new Label(" "*LabelInitialSize) textDisplay.horizontalAlignment = Alignment.Center // FIXME def setText(s:String) { textDisplay.text = "user action: " + s } // // container with some buttons // val buttons = new FlowPanel { contents += Button("button 1") { setText("clicked button 1") } contents += Button("button 2") { setText("clicked button 2") } } // // menu with some items // val menu = new Menu("Actions") { contents += new MenuItem(Action("item 1") { setText("chose menu item 1") } ) contents += new MenuItem(Action("item 2") { setText("chose menu item 2") } ) } // // list with selectable entries // val list = new ListView(List("this", "that", "the other thing", "another")) // // main frame/window // val frame = new MainFrame { title = "Hello!" contents = new BoxPanel(Orientation.Vertical) { contents += buttons contents += new FlowPanel { contents += list } contents += new FlowPanel { contents += textDisplay } } menuBar = new MenuBar { contents += menu } // // update label when list selection changes // listenTo(list.selection) reactions += { case e:SelectionChanged => { setText("selected list items " + list.selection.items.mkString(", ")) } } // // no size here -- use pack below // } // set size to just big enough to hold all components frame.pack // display frame.visible = true