如何使用 Groovy SwingBuilder 创建一个 JDesktopPand/JInternalFrame 组合?
How to use Groovy SwingBuilder to create a JDesktopPand/JInternalFrame combo?
我正在尝试使用 SwingBuilder 创建 Groovy MDI 应用程序。
我从 http://groovy-lang.org/swing.html 的基本 SwingBuilder 示例开始,并添加了对 desktopPane
和 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)
}
}
}
}
然而,这段代码只会给我一个空白 window。
看来我只需要将 visible
和 bounds
参数添加到 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)
}
}
}
}
我正在尝试使用 SwingBuilder 创建 Groovy MDI 应用程序。
我从 http://groovy-lang.org/swing.html 的基本 SwingBuilder 示例开始,并添加了对 desktopPane
和 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)
}
}
}
}
然而,这段代码只会给我一个空白 window。
看来我只需要将 visible
和 bounds
参数添加到 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)
}
}
}
}