(1) 逐一佈建
import groovy.swing.SwingBuilder import java.awt.* import javax.swing.* def swing = new SwingBuilder() swing.edt { frame ( title: "Ex", defaultCloseOperation: JFrame.EXIT_ON_CLOSE, pack: true, show: true ) { borderLayout() panel(constraints: BorderLayout.CENTER) { borderLayout() panel(constraints: BorderLayout.PAGE_START) { label(text: 'header') } panel(constraints: BorderLayout.CENTER) { label(text: 'center 1') } panel(constraints: BorderLayout.PAGE_END) { label(text: 'footer') } } } }(2) 先簡單的佈建, 接著再佈置主要的 panel (以避免擁擠、縮排過深)
import groovy.swing.SwingBuilder import java.awt.* import javax.swing.* def swing = new SwingBuilder() swing.edt { frame ( title: "Ex", defaultCloseOperation: JFrame.EXIT_ON_CLOSE, pack: true, show: true ) { borderLayout() panel(constraints: BorderLayout.PAGE_START) { borderLayout() panel(constraints: BorderLayout.PAGE_START) { label(text: 'header') } panel(constraints: BorderLayout.PAGE_END) { label(text: 'footer') } }.add( panel(constraints: BorderLayout.CENTER) { label(text: 'center 2') }) } }(3) 先簡單的佈建, 事後再佈置主要的 panel
import groovy.swing.SwingBuilder import java.awt.* import javax.swing.* def swing = new SwingBuilder() def thePanel swing.edt { frame ( title: "Ex", defaultCloseOperation: JFrame.EXIT_ON_CLOSE, pack: true, show: true ) { borderLayout() thePanel = panel(constraints: BorderLayout.CENTER) { borderLayout() panel(constraints: BorderLayout.PAGE_START) { label(text: 'header') } panel(constraints: BorderLayout.PAGE_END) { label(text: 'footer') } } ... ... thePanel.add( panel(constraints: BorderLayout.CENTER) { label(text: 'center 3') }) } }
沒有留言:
張貼留言