在swt中使用table

    不經常寫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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章