gridbagdemo.scala

来自「JAVA 语言的函数式编程扩展」· SCALA 代码 · 共 64 行

SCALA
64
字号
package scala.swing.testimport swing._import swing.event._import GridBagPanel._import java.awt.Insetsobject GridBagDemo extends SimpleGUIApplication {  val ui = new GridBagPanel {    val c = new Constraints    val shouldFill = true    if (shouldFill) {      c.fill = Fill.Horizontal    }    val button1 = new PushButton("Button 1")    c.weightx = 0.5    c.fill = Fill.Horizontal    c.gridx = 0;    c.gridy = 0;    layout(button1) = c    val button2 = new PushButton("Button 2")    c.fill = Fill.Horizontal    c.weightx = 0.5;    c.gridx = 1;    c.gridy = 0;    layout(button2) = c    val button3 = new PushButton("Button 3")    c.fill = Fill.Horizontal    c.weightx = 0.5;    c.gridx = 2;    c.gridy = 0;    layout(button3) = c    val button4 = new PushButton("Long-Named Button 4")    c.fill = Fill.Horizontal    c.ipady = 40;      //make this component tall    c.weightx = 0.0;    c.gridwidth = 3;    c.gridx = 0;    c.gridy = 1;    layout(button4) = c    val button5 = new PushButton("5")    c.fill = Fill.Horizontal    c.ipady = 0;       //reset to default    c.weighty = 1.0;   //request any extra vertical space    c.anchor = Anchor.PageEnd    c.insets = new Insets(10,0,0,0);  //top padding    c.gridx = 1;       //aligned with button 2    c.gridwidth = 2;   //2 columns wide    c.gridy = 2;       //third row    layout(button5) = c  }    def top = new MainFrame {    title = "GridBag Demo"    contents = ui  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?