#topicpath
----
#contents
**スレッド
SWTはメインスレッド以外のスレッドがGUIコンポーネントにアクセすると例外が発生するようです。じゃあどうすればよいかっていうと、Display#asyncExec(スレッド) というメソッドを使って、メインスレッドにGUI処理を委譲するという方法をとります。((どうも、この方法でやってもスレッド処理されないなあって思ってたんですが、GUI処理以外の処理も委譲させてました。。GUI処理だけ委譲するって考え方ですねっ))


**スニペット
 package kino.swt;
 
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
 
 public class Main {
 	/**
 	 * Form上のコンポーネントを配置する
 	 * @param display
 	 * @return
 	 */
 	public Shell open(Display display) {
 		final Shell shell = new Shell(display);
 
 		// DESIGNER: Add controls before this line.
 		shell.setSize(500, 300);
 		shell.pack();
 		shell.open();
 		return shell;
 	}
 
 	public static void main(String[] args) {
 		Main main = new Main();
 		Display display = new Display();
 		Shell shell = main.open(display);
 
 		while (!shell.isDisposed()) {
 			if (!display.readAndDispatch())
 				display.sleep();
 		}
 		display.dispose();
 		System.exit(0);
 	}
 
 }





** 外部アプリケーションを起動する
:使用クラス|org.eclipse.swt.program.Program

 Program program=Program.findProgram("html"); <- この拡張子のアプリケーションを探す
 program.execute("http://などURL"); <- アプリケーション起動
とすると、デフォルトのブラウザが起動し、指定したURLが開きます。

** めいっぱい配置
 final GridData gridData = new GridData(GridData.FILL_HORIZONTAL);

** グリッドの列を何列にするか?
 GridLayout gridLayout = new GridLayout();
 gridLayout.numColumns = 3;
 shell.setLayout(gridLayout);

** ShellのCloseのイベントで何かしたい
 shell.addListener(SWT.Close, new CloseCheck());
として内部クラスで
 class CloseCheck implements Listener {
 	public void handleEvent(Event event) {
 		System.out.println("CloseCheck called");
 		MessageBox box =
 			new MessageBox(
 				shell,
 				SWT.APPLICATION_MODAL
 					| SWT.ICON_QUESTION
 					| SWT.YES
 					| SWT.NO);
 
 		box.setMessage("本当に終了する?");
 		box.setText("Application の終了");
 		int answer = box.open();
 		if (answer == SWT.NO) {
 			event.doit = false;
 		}
 
 	}
 }
終了してよいかのダイアログを出す

*** LinuxでSWT
http://www-6.ibm.com/jp/developerworks/java/030711/j_j-nativegui2.html

 cp -p *.so /usr/lib
 export LD_LIBRARY_PATH=/usr/lib:$LD_LIBRARY_PATH
 java -cp .:lib/:lib/log4j-1.2.8.jar:lib/kino_javadocsearch.jar:lib/swt.jar:lib/swt-pi.jar kino.swt.JavaDocSearchForm



----
この記事は
#vote(おもしろかった,そうでもない)

#comment
#topicpath


SIZE(10){現在のアクセス:&counter;}

トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS