IBM SWT 表

是支持 TableColumns 的列表的增强形式。这些列将它们的数据对齐成一种更可读的形式。它们还支持列名,并能调整列的大小。要创建表,首先要创建表控件,然后添加 TableItems 中包装的字符串数据。

表支持以下可选样式:

  • CHECK 将复选框添加到第一列中。
  • VIRTUAL 支持大型表(特定于平台)。
  • FULL_SELECTION 选择所有列(不仅仅是第一列)。

清单 6 创建了图 6 中所示的表。 

 


// Create the Table and TableColumns
protected Table createTable(Composite parent, int mode, Object[] contents) {
    table = new Table(parent, mode | SWT.SINGLE | SWT.FULL_SELECTION |
                      SWT.V_SCROLL | SWT.H_SCROLL);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    createTableColumn(table, SWT.LEFT,   "Column 1", 100);
    createTableColumn(table, SWT.CENTER, "Column 2", 100);
    createTableColumn(table, SWT.RIGHT,  "Column 3", 100);
    addTableContents(contents);
    return table;
}
protected TableColumn createTableColumn(Table table, int style, String title, int width) {
    TableColumn tc = new TableColumn(table, style);
    tc.setText(title);
    tc.setResizable(true);
    tc.setWidth(width);
    return tc;
}
protected void addTableContents(Object[] items) {
    for (int i = 0; i < items.length; i++) {
        String[] item = (String[])items[i];
        TableItem ti = new TableItem(table, SWT.NONE);
        ti.setText(item);
    }
}
  :
// sample creation code
protected void initGui() {
    Object[] items = {
        new String[] {"A", "a", "0"}, new String[] {"B", "b", "1"},
        new String[] {"C", "c", "2"}, new String[] {"D", "d", "3"},
        new String[] {"E", "e", "4"}, new String[] {"F", "f", "5"},
        new String[] {"G", "g", "6"}, new String[] {"H", "h", "7"},
        new String[] {"I", "i", "8"}, new String[] {"J", "j", "9"}
    };
    table = createTable(this, SWT.CHECK, items);
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值