SWTアプリで別ウィンドウを立ち上げる
ソースコードはこんな感じです。
メイン側から呼び出すところ
/** アクション 「自炊補助ツールについて」 */ private class AboutJisuiAction extends Action { ApplicationWindow window; public AboutJisuiAction(ApplicationWindow w) { window = w; setText("自炊補助ツールについて"); } public void run() { AboutDialog abouotDialog = new AboutDialog(window.getShell()); abouotDialog.open(); } }
呼び出されるウィンドウ
package jp.kashiwa; import java.io.IOException; import java.io.InputStream; import java.util.Properties; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Dialog; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; public class AboutDialog extends Dialog { private Shell shell; public AboutDialog(Shell parent, int style) { super(parent, style); } public AboutDialog(Shell parent) { this(parent, SWT.None); } public int open() { createContents(); shell.open(); shell.layout(); Display display = getParent().getDisplay(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } return SWT.OK; } private void createContents() { shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); shell.setSize(300, 300); shell.setText("自炊補助ツールについて"); shell.setImage(new Image(shell.getDisplay(), this.getClass().getClassLoader().getResourceAsStream("image/pdf.ico"))); GridLayout gridLayout = new GridLayout(1, false); shell.setLayout(gridLayout); Label versionLabel = new Label(shell, SWT.NONE); versionLabel.setText("自炊補助ツール バージョン " + getVersion()); Label updateLabel = new Label(shell, SWT.NONE); updateLabel.setText("更新日 " + getUpdateDate()); Label copylightLabel = new Label(shell, SWT.NONE); copylightLabel.setText("Copyright (C)2011 By Takahiro Yamaki"); (省略) Button okButton = new Button(shell, SWT.NONE); okButton.setText("OK"); okButton.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent selectionevent) { shell.close(); } @Override public void widgetDefaultSelected(SelectionEvent selectionevent) { } }); } /** @return バージョン */ (省略) /** @return 更新日付 */ (省略) }
実物
自炊補助(PDF編集)ツールのダウンロードはこちら