1

我正在尝试使用 SwingBuilder 创建一个 Groovy MDI 应用程序。

我从http://groovy-lang.org/swing.htmldesktopPane上的基本 SwingBuilder 示例开始,并添加了对and的调用internalFrame

import groovy.swing.SwingBuilder
import java.awt.BorderLayout as BL

count = 0
new SwingBuilder().edt {
  frame(title: 'Frame', size: [300, 300], show: true) {
    desktopPane() {
      internalFrame() {
        borderLayout()
        textlabel = label(text: 'Click the button!', constraints: BL.NORTH)
        button(text:'Click Me',
             actionPerformed: {count++; textlabel.text = "Clicked ${count} time(s)."; println "clicked"}, constraints:BL.SOUTH)
      }
    }
  }
}

但是,这段代码只会给我一个空白窗口。

4

1 回答 1

1

看起来我只需要添加visiblebounds参数internalFrame

import groovy.swing.SwingBuilder
import java.awt.BorderLayout as BL

count = 0
new SwingBuilder().edt {
  frame(title: 'Frame', size: [300, 300], show: true) {
    desktopPane() {
      internalFrame(visible: true, bounds: [25, 25, 200, 100]) {
        borderLayout()
        textlabel = label(text: 'Click the button!', constraints: BL.NORTH)
        button(text:'Click Me',
             actionPerformed: {count++; textlabel.text = "Clicked ${count} time(s)."; println "clicked"}, constraints:BL.SOUTH)
      }
    }
  }
}
于 2018-03-21T11:20:30.033 回答