+ Creating a JFace ApplicationWindow with MenuBar Joris Van den Bogaert Main.java: import org.eclipse.jface.dialogs.*; import org.eclipse.jface.action.*; import org.eclipse.jface.window.*; import org.eclipse.swt.widgets.*; import org.eclipse.swt.*; public class Main extends ApplicationWindow { public Main(Shell parent) { super(parent); } public static void main(String []args) { Display display = new Display(); Shell shell = new Shell(display); Main main = new Main(shell); main.createComponents(); main.open(); } public void createComponents() { setBlockOnOpen(true); addMenuBar(); } protected MenuManager createMenuManager() { MenuManager menuManager = new MenuManager(); menuManager.add(createFileMenu()); return menuManager; } protected MenuManager createFileMenu() { MenuManager menu = new MenuManager("&File", "Id01"); menu.add(new Action() { public String getText() { return "&Open"; } public void run() { String[] buttons = { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }; MessageDialog dialog = new MessageDialog(getShell(), "Title", null, "File/Open selected!", MessageDialog.INFORMATION, buttons, 0); dialog.open(); // blocking call } }); menu.add(new Action() { public String getText() { return "E&xit"; } public void run() { Main.this.getParentShell().close(); } }); return menu; } protected void configureShell(Shell shell) { super.configureShell(shell); shell.setSize(300, 200); shell.setText("Example JFace with MenuBar"); } }
Creating a JFace ApplicationWindow with MenuBar
Joris Van den BogaertMain.java: