SWT Tips and Samples 基礎編 > FontDialog

 

FontDialog

FontDialogはフォントを選択するためのダイアログです。他のダイアログと同様にopenメソッド実行後ダイアログが表示され、戻り値としてFontDataを得られます。またキャンセルボタンが押されるとnullが返ります。

スクリーンショット

ソースコード (FontDialogTest.java)

import org.eclipse.swt.widgets.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.layout.*;

public class FontDialogTest {

        private Shell shell;
        private Label label;

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

                GridLayout gl = new GridLayout(1, false);
                shell.setLayout(gl);
                
                label = new Label(shell, SWT.BORDER);
                label.setText("Test String");
                GridData gd = new GridData();
                gd.widthHint = 200;
                gd.heightHint = 100;
                label.setLayoutData(gd);
                
                Button b = new Button(shell, SWT.PUSH);
                b.setText("Open Font Dialog");
                
                b.addSelectionListener(new SelectionAdapter(){
                        public void widgetSelected(SelectionEvent e) {
                            FontDialog dialog = new FontDialog(shell);
                            FontData fd = dialog.open();
                            if (fd == null){
                                return;
                            }
                            Font font = new Font(shell.getDisplay(), fd);
                            label.setFont(font);
                        }

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


最新更新日: 2004年8月31日
 
関連リンク
Eclipse API ドキュメント
FontDialog
Font
FontData

- PR -

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

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

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

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

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


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