📄 imagemenudemo.java
字号:
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.*;
public class ImageMenuDemo {
public static Display myDisplay;
public static boolean internalCall = false;
public static void main(String[] args) {
internalCall = true;
myDisplay = new Display();
ImageMenuDemo imd = new ImageMenuDemo();
imd.runDemo(myDisplay);
}
public void runDemo(Display display) {
myDisplay = display;
Shell shell = new Shell(display);
shell.setSize(100,100);
shell.setText("Image Menu Demo");
shell.open();
//load an image from a BMP file, to act
//as the icon for our menu item
//Image icon = new Image(display, "arrow.bmp");
Image icon = new Image(display, "splash.jpg");
//create a standard menu bar with a file menu
//and action option
Menu bar = new Menu(shell, SWT.BAR);
shell.setMenuBar(bar);
MenuItem file = new MenuItem(bar, SWT.CASCADE);
file.setText("File");
Menu fileMenu = new Menu(shell, SWT.DROP_DOWN);
MenuItem action = new MenuItem(fileMenu, SWT.PUSH);
file.setMenu(fileMenu);
action.setText("Action");
//set the image for the Action MenuItem
action.setImage(icon);
while (!shell.isDisposed())
if (!display.readAndDispatch())
display.sleep();
if (internalCall) display.dispose();
icon.dispose();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -