开发者

How to add a header to a Groovy SwingBuilder table?

How do I add a header to the table defined below?

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', propertyN开发者_开发技巧ame:'last')
        }
    }
}
frame.pack()
frame.show()


If you put the table in a scrollPane, the headers appear:

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()

See item one on this page for an explanation why


Table header is a separate widget that must be added explicitly.

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()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜