如何将标头添加到Groovy SwingBuilder表?

时间:2010-08-25 18:27:43

标签: groovy swingbuilder

如何在下面定义的表格中添加标题?

import groovy.swing.SwingBuilder

data = [[first:'qwer', last:'asdf'],
        [first:'zxcv', last:'tyui'],
        [first:'ghjk', last:'bnm']]

swing = new SwingBuilder()
frame = swing.frame(title:'table test'){
    table {
        tableModel( list : data ) {
            propertyColumn(header:'First Name', propertyName:'first')
            propertyColumn(header:'last Name', propertyName:'last')
        }
    }
}
frame.pack()
frame.show()

2 个答案:

答案 0 :(得分:5)

如果您将表格放在scrollPane中,标题会显示:

import groovy.swing.SwingBuilder

data = [[first:'qwer', last:'asdf'],
        [first:'zxcv', last:'tyui'],
        [first:'ghjk', last:'bnm']]

swing = new SwingBuilder()
frame = swing.frame(title:'table test'){
  scrollPane {
    table {
        tableModel( list : data ) {
            propertyColumn(header:'First Name', propertyName:'first')
            propertyColumn(header:'last Name', propertyName:'last')
        }
    }
  }
}
frame.pack()
frame.show()

请参阅第一项on this page以获取解释原因

答案 1 :(得分:1)

表标题是必须明确添加的单独小部件。

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

data = [[first:'qwer', last:'asdf'],
        [first:'zxcv', last:'tyui'],
        [first:'ghjk', last:'bnm']]

swing = new SwingBuilder()
frame = swing.frame(title:'table test'){
    def tab = table(constraints:BorderLayout.CENTER) {
        tableModel( list : data ) {
            propertyColumn(header:'First Name', propertyName:'first')
            propertyColumn(header:'Last Name', propertyName:'last')
        }
    }
    widget(constraints:BorderLayout.NORTH, tab.tableHeader)
}
frame.pack()
frame.show()