SWT Tips and Samples 基礎編 > ViewForm

 

ViewForm

ViewFormとは、Eclipseのビューとして使われているウィジェットです。タイトルバーを配置するメソッドが用意されているので、クールなデザインのサブウィンドウを簡単に作れます。非常に便利なウィジェットです。ViewFormのスタイルは、BORDERかFLATを指定できます。

Shell shell = ...;
ViewForm vf = new ViewForm(shell, SWT.BORDER);

Label label = new Label(vf, ...);
Text text = new Text(vf, ...);
...

//ViewFormにウィジェットを配置するメソッド
vf.setTopLeft(label);
vf.setTopCenter(label);
vf.setTopRight(label);

//コンテンツを追加するメソッド
vf.setContent(text);

//TopとContentの間にセパレーターを入れる場合
vf.setTopCenterSeparate(true);

サンプルプログラム

下のサンプルプログラムは、Styleを変えた場合のViewFormの表示例です。ラベルをLeft, Center, Rightの三つの個所に配置し、Contentにはテキストウィジェットを配置しました。setTopCenterSeparatorをTRUEにするとTopとContentの間にウィジェットが表示されるのが分かると思います。FALSEにした場合は、TopRightのすぐ左側にウィジェットが表示されます。

ソースコード (ViewFormTest.java)

import org.eclipse.swt.widgets.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.custom.ViewForm;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.*;

public class ViewFormTest {

        private Image img;
        
        public static void main(String[] args) {
                new ViewFormTest();
        }
        public ViewFormTest() {
                Display display = new Display();
                Shell shell = new Shell(display);
                shell.setText("ViewFormTest");
                
                img = new Image(display, "icon.gif");

                shell.setLayout(new GridLayout(1, false));
                
                ViewForm vf1 = new ViewForm(shell, SWT.BORDER);
                vf1.setLayoutData(new GridData(GridData.FILL_BOTH));
                vf1.setTopCenterSeparate(false);
                createWidgets(vf1, "StyleがBORDER、Separatorがない場合");
                
                ViewForm vf2 = new ViewForm(shell, SWT.BORDER);
                vf2.setLayoutData(new GridData(GridData.FILL_BOTH));
                vf2.setTopCenterSeparate(true);
                createWidgets(vf2, "StyleがBORDER、Separatorがある場合");
                
                ViewForm vf3 = new ViewForm(shell, SWT.FLAT);
                vf3.setLayoutData(new GridData(GridData.FILL_BOTH));
                vf3.setTopCenterSeparate(true);
                createWidgets(vf3, "StyleがFLAT、Separatorがある場合");
                
                shell.setSize(350,350);
                shell.open();
                while (!shell.isDisposed()) {
                        if (!display.readAndDispatch()) {
                                display.sleep();
                        }
                }
                display.dispose();
        }

        private void createWidgets(ViewForm vf, String content) {
                CLabel topLeft = new CLabel(vf, SWT.NONE);
                topLeft.setText("TopLeft");
                topLeft.setImage(img);
                vf.setTopLeft(topLeft);
                
                CLabel l2 = new CLabel(vf, SWT.NONE);
                l2.setText("TopCenter");
                vf.setTopCenter(l2);
 
                CLabel topRight = new CLabel(vf, SWT.NONE);
                topRight.setText("TopRight");
                vf.setTopRight(topRight);
                
                Text t = new Text(vf, SWT.MULTI | 
                                      SWT.V_SCROLL);
                t.setText("Content: \n" + content);
                vf.setContent(t);
        }
}


最新更新日: 2004年7月25日
 
関連リンク
Eclipse API ドキュメント
ViewForm
CLabel
Image

- PR -

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

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

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

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

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


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