SWT Tips and Samples 基礎編 > ColorDialog

 

ColorDialog

ColorDialogは色を選択するためのダイアログです。ColorDialogのopenメソッドを実行すると、下のようなダイアログが表示され、戻り値としてRGBが返ります。キャンセルボタンが押された場合、nullが返されます。下のサンプルプログラムは、ColorDialogでLabelの背景色を変えることができます。

スクリーンショット

ソースコード (ColorDialogTest.java)

import org.eclipse.swt.widgets.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.*;

public class ColorDialogTest {

        private Shell shell;
        
        private Label label;

        public static void main(String[] args) {
                new ColorDialogTest();
        }
        public ColorDialogTest() {
                Display display = new Display();
                shell = new Shell(display);
                shell.setText("ColorDialogTest");

                shell.setLayout(new FillLayout(SWT.HORIZONTAL));
                
                label = new Label(shell, SWT.BORDER);
                
                Button b = new Button(shell, SWT.PUSH);
                b.setText("Open Color Dialog");
                
                b.addSelectionListener(new SelectionAdapter(){
                        public void widgetSelected(SelectionEvent e) {
                                ColorDialog dialog = new ColorDialog(shell);
                                RGB rgb = dialog.open();
                                if (rgb == null){
                                        return;
                                }
                                System.out.println("Selected Color: " + rgb);
                                Color color = new Color(shell.getDisplay(), rgb);
                                label.setBackground(color);
                                color.dispose();
                        }

                });
                
                shell.pack();
                shell.open();
                while (!shell.isDisposed()) {
                        if (!display.readAndDispatch()) {
                                display.sleep();
                        }
                }
                display.dispose();
        }
}


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

- PR -

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

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

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

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

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


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