SWT Tips and Samples 基礎編 > DirectoryDialog

 

DirectoryDialog

ディレクトリを選択するためのダイアログです。これまで出てきたダイアログと同様にopenメソッドを実行するとダイアログが表示され、戻り値として選択されたディレクトリの文字列が返ります。キャンセルが押下された場合、nullが返ります。またsetFilterPathメソッドで初期ディレクトリ、setMessageメソッドでダイアログに表示されるメッセージを指定可能です。

DirectoryDialogのコンストラクタDirectoryDialog(Shell parent, int style)でスタイルも指定できますが、ここで指定されたスタイルはスーパークラスであるDialogに適応されます。

スクリーンショット

ソースコード (DirectoryDialogTest.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.layout.*;

public class DirectoryDialogTest {

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

                Button button = new Button(shell, SWT.PUSH);
                button.setText("Open Directory Dialog");
                button.addSelectionListener(new SelectionAdapter(){
                   public void widgetSelected(SelectionEvent e) {
                          //コンストラクタで指定されるスタイルは、Dialogクラスに適応される。
                          DirectoryDialog dialog = new DirectoryDialog(shell);
                          dialog.setFilterPath("c:\\");
                          dialog.setMessage("ここにメッセージを設定できます。");
                           String dir = dialog.open();
                           if (dir == null){
                               return;
                           }
                           System.out.println("Selected Directory: " + dir);
                   }

                });

                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] 爆速!無料ブログ 無料ホームページ開設 無料ライブ放送