SWT Tips and Samples 基礎編 > Table

 

Table

SWTのTableはSwingのテーブルに比べ容易に実装が可能です。TableのコンストラクタでTableの振る舞いや表示を指定することができます。

SWTが提供しているTableは、 非常にシンプルで使いやすいのですが、モデルとビューを切り分けてTableを使った実装をしたいときは、JFaceライブラリに用意されているTableViewerクラスを利用することをお勧めします。 詳しくは、下の参考リンクを参照してください。

スクリーンショット

ソースコード (TableLayoutTest.java)

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class TableTest {
        public static void main(String[] args) {
                new TableTest();
        }
        public TableTest() {
                Display display = new Display();
                Shell shell = new Shell(display);
                shell.setText("TableTest");
                shell.setLayout(new FillLayout());
                
                Table table1 = new Table(shell, SWT.MULTI | SWT.BORDER);
                table1.setHeaderVisible(true);
                createTableColAndContents(table1);
                
                Table table2 = new Table(shell, SWT.SINGLE | 
                                                SWT.BORDER | 
                                                SWT.FULL_SELECTION);
                table2.setLinesVisible(true);
                createTableColAndContents(table2);
                
                shell.pack();
                shell.open();
                while (!shell.isDisposed()) {
                        if (!display.readAndDispatch()) {
                                display.sleep();
                        }
                }
                display.dispose();
        }
        
        private void createTableColAndContents(Table table){
                for (int i=0; i<4; i++){
                        TableColumn col = new TableColumn(table, SWT.LEFT);
                        col.setText("Col" + i);
                        col.setWidth(60);
                }
                for (int i=0; i<10; i++){
                        String [] contents = {"Item0-" + i, 
                                              "Item1-" + i, 
                                              "Item2-" + i, 
                                              "Item3-" + i};
                        TableItem tableItem = new TableItem(table, SWT.NONE);
                        tableItem.setText(contents);
                }
                
                
        }
}

参考



最新更新日: 2004年10月20日
 
関連リンク
Eclipse API ドキュメント
Table

- PR -

プレゼンテーション作成ソフト無料お試し版配信中

【Sony】大手他社よりも安い!ビジネス向け光・100Mしかも固定IP付!今なら更に初期費用最大15,000円OFF!

オフィス用品・オフィス家具 価 格 交 渉 可! 
◎ 目指せ★業界最安値 ★ ◎ オフィネット・ドットコム株式会社

注文から納品まで驚きの早さ!!【ASKULカタログ】はこちらから・・・

マイクロソフト お得な見積! まとめての購入ならオトクな方法で。ライセンスだから管理も簡単。


Copyright(C) 2003,2004 Jasmin Project. All Right Reserved.
SEO [PR] 爆速!無料ブログ 無料ホームページ開設 無料ライブ放送