在swt中使用table

来源:互联网 发布:转卖二手物品的软件 编辑:程序博客网 时间:2024/04/27 09:05

    不经常写swt的东西,每次写都要翻阅几次swt的官方demo,今天要实现个table,但是在官方的例子中却找不到如何在table的一行中插入一个checkbox,在swt中checkbox就是button,于是开始百度,swt的资料真的比较少,百度一圈找了些代码碎片组合在了一起就成下面的demo了,其实swt的官方demo中好像没有介绍TableEditor ,可能是我没看到,这个类可以替换一个列内的控件,从下面代码可以看出他的功能.

package com.nstc;import java.util.ArrayList;import java.util.List;import org.eclipse.swt.SWT;import org.eclipse.swt.custom.TableEditor;import org.eclipse.swt.graphics.Color;import org.eclipse.swt.layout.FillLayout;import org.eclipse.swt.widgets.Button;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Shell;import org.eclipse.swt.widgets.Table;import org.eclipse.swt.widgets.TableColumn;import org.eclipse.swt.widgets.TableItem;/** * 

* Title:SWT Table 示例 *

* * * @author 孙钰佳 * * @since:2008-6-10 下午04:28:06 * * @version 1.0 */public class SwtTableDemo {private static void createTable(Shell shell) {Table table = new Table(shell, SWT.FULL_SELECTION | SWT.HIDE_SELECTION| SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);table.setHeaderVisible(true); // 显示表头table.setLinesVisible(true); // 显示网格线List tableColumns = new ArrayList();for (int i = 0; i < 100; i++) {// 插入列TableColumn tableColumn = new TableColumn(table, SWT.NONE);tableColumn.setWidth(30);tableColumn.setText(i+"");tableColumns.add(tableColumn);}List tableEditors = new ArrayList();List
原创粉丝点击