📄 simplemenudemo.java
字号:
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;
public class SimpleMenuDemo {
public static Display myDisplay;
public static boolean internalCall = false;
public static void main(String[] args) {
internalCall = true;
myDisplay = new Display();
SimpleMenuDemo md = new SimpleMenuDemo();
md.runDemo(myDisplay);
}
public void runDemo(Display display) {
myDisplay = display;
Shell shell = new Shell(display);
shell.setText("Simple Menu Demo");
//create the menu bar
Menu menu = new Menu(shell, SWT.BAR);
shell.setMenuBar(menu);
//add the File option to it
MenuItem file = new MenuItem(menu, SWT.CASCADE);
file.setText("File");
//create a menu for the File option
Menu filemenu = new Menu(shell, SWT.DROP_DOWN);
file.setMenu(filemenu);
//add a MenuItem to the File menu
MenuItem actionItem = new MenuItem(filemenu, SWT.PUSH);
actionItem.setText("Action");
//add a listener for the action
actionItem.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
System.out.println("Action performed!");
}
});
shell.setSize(300,300);
shell.open();
while(!shell.isDisposed())
if(!display.readAndDispatch())
display.sleep();
if (internalCall) display.dispose();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -