WindowsBuilder のインストールとプロジェクトの作成 ▼ 以下を参照して下さい Pleiades All in One で、Windows アプリを作成する手順( WindowBuilder + Swing デザイナー or SWT デザイナー[JFace] ) ApplicationWindow を中央に表示
@Override protected Point getInitialLocation(Point initialSize) { GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); // デスクトップのサイズ Point windowSize = new Point( env.getMaximumWindowBounds().width, env.getMaximumWindowBounds().height); Point position = new Point(0,0); // デスクトップの中心に表示します return new Point( position.x + ((windowSize.x - initialSize.x) / 2), position.y + ((windowSize.y - initialSize.y) / 2) ); }
ダイアログの呼び出し 呼び出し先から、こちら側のコントロールにアクセスする為、識別する為に名前を setData でセットしています
Button btnNewButton = new Button(container, SWT.NONE); btnNewButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { Dialog1 dialog = new Dialog1(getShell()); int result = dialog.open(); System.out.println(result); } }); btnNewButton.setBounds(10, 10, 75, 25); btnNewButton.setText("New Button"); btnNewButton.setData("name","Button1");
ダイアログを親ウインドウの中央に
@Override protected Point getInitialLocation(Point initialSize) { Point windowSize = this.getShell().getParent().getSize(); Point position = this.getShell().getParent().getLocation(); return new Point( position.x + ((windowSize.x - initialSize.x) / 2), position.y + ((windowSize.y - initialSize.y) / 2) ); }
ダイアログから親ウインドウにアクセス 対症療法なので正確では無いですが、parentShell.getChildren() の内容にもう少しチェックを追加すれば使用に問題は無いと思います。コンストラクタにウインドウのインスタンスを渡せば簡単ですが、汎用性はこちらのほうが勝ると思います。
@Override protected void createButtonsForButtonBar(Composite parent) { Button button = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); button.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { Shell parentShell = Dialog1.this.getParentShell(); Control[] controls = parentShell.getChildren(); Composite con = (Composite)controls[1]; controls = con.getChildren(); for( Control control: controls ) { Object name = control.getData("name"); if ( name != null) { if ( name.toString().equals("Button1") ) { Button btn = (Button) controls[0]; btn.setText("ボタン"); break; } } } Dialog1.this.setReturnCode(Dialog.OK); Dialog1.this.close(); } }); Button button_1 = createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); button_1.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { Dialog1.this.setReturnCode(Dialog.CANCEL); Dialog1.this.close(); } }); }
|
【Pleiadesの最新記事】
- ロリポップ用ログインブックマークレット( ユーザ専用ページ・phpMyAdmin・WEBメーラ )
- Pleiades Oxygen + WindowsBuilder で MySQL を使用して SQL(select) からデータの一覧を表示する
- Pleiades Oxygen の XAMPP の TOMCAT を Pleiades の JDK8 で動作させる
- Pleiades Eclipse 4.7 Oxygen 2 Windows 64bit Ultimate Full Edition のインストールといろいろな準備
- Pleiades Oxygen 2 の XAMPP 内の MercuryMail をインストールして使用する
- XAMPP 内の MySQL を利用可能にしてテストデータ(販売管理)を登録する
- Pleiades Oxygen 2 の XAMPP 内の FileZilla Server をインストールして使用する