SWT Tips and Samples 基礎編 > MenuManager |
|
MenuManagerMenuManagerはApplicationWindowでメニューを作成するときに使います。 メニューアイテムとActionの対応JFaceのフレームワークを使った場合、メニューアイテムはActionクラスを継承したインスタンスと一対一関係になります。チェックボックスやラジオボタン形式のメニューアイテムを作るには、Actionクラスのコンストラクタを以下のように呼びます。この例の場合、チェックボックス型のメニューアイテムが作られます。メニューがチェックされているどうか調べるには、Action.isChecked()メソッドを用いれば分かります。 class CheckBoxAction extends Action { public CheckBoxAction() { super("CHECKBOX_ACTION", Action.AS_CHECK_BOX); setText("CheckBox"); } public void run() { ... } } 以下に示すのは、Actionクラスに用意されたメニューアイテムのタイプを示す定数です。
なおsuperメソッドをコンストラクタで省略した場合は、デフォルトでAS_PUSH_BUTTONが設定されます。 メニューバーの境界線についてメニューに境界線(セパレータ)を追加するには、MenuManagerにSeparatorオブジェクトを追加します。 MenuManager mm = new MenuManager("&File"); .... mm.add(new org.eclipse.jface.action.Separator()); .. サンプルアプリケーションソースコード (MenuManagerTest.java)import org.eclipse.jface.action.Action; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.Separator; import org.eclipse.jface.window.ApplicationWindow; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.*; import org.eclipse.swt.widgets.*; public class MenuManagerTest extends ApplicationWindow { private Action pushAction; private Action checkBoxAction; private Action radioAction1; private Action radioAction2; private Label label; public MenuManagerTest() { super(null); pushAction = new PushAction(); checkBoxAction = new CheckBoxAction(); radioAction1 = new RadioAction(); radioAction2 = new RadioAction(); addMenuBar(); } public static void main(String[] args) { ApplicationWindow w = new MenuManagerTest(); w.setBlockOnOpen(true); w.open(); Display.getCurrent().dispose(); } protected Control createContents(Composite parent) { getShell().setText("MenuManagerTest"); Composite container = new Composite(parent, SWT.NONE); container.setLayout(new GridLayout(1, true)); label = new Label(container, SWT.NONE); label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); label.setText("message"); return container; } protected MenuManager createMenuManager() { MenuManager menuBar = new MenuManager(""); MenuManager fileMenu = new MenuManager("&File"); MenuManager newMenu = new MenuManager("&New"); fileMenu.add(newMenu); newMenu.add(pushAction); fileMenu.add(checkBoxAction); fileMenu.add(new Separator()); fileMenu.add(radioAction1); fileMenu.add(radioAction2); menuBar.add(fileMenu); return menuBar; } class CheckBoxAction extends Action { public CheckBoxAction() { super("CHECKBOX_ACTION", Action.AS_CHECK_BOX); setText("CheckBox"); } public void run() { label.setText("Checkbox is selected."); } } class RadioAction extends Action { public RadioAction() { super("RADIO", Action.AS_RADIO_BUTTON); setText("Radio"); } public void run() { label.setText("Radio is selected."); } } class PushAction extends Action{ public PushAction(){ super("PUSH", Action.AS_PUSH_BUTTON); setText("Push"); } public void run(){ label.setText("Push is selected."); } } } 最新更新日: 2004年10月20日 |
- PR -
【Sony】大手他社よりも安い!ビジネス向け光・100Mしかも固定IP付!今なら更に初期費用最大15,000円OFF!
オフィス用品・オフィス家具 価 格 交 渉 可!
|
||||
|
|||||
Copyright(C) 2003,2004 Jasmin Project. All Right Reserved. |
SEO | [PR] 爆速!無料ブログ 無料ホームページ開設 無料ライブ放送 | ||