下面列出了怎么用org.eclipse.swt.widgets.Tray的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Open the window.
*/
public void open() {
try {
Display display = Display.getDefault();
this.createContents();
this.shell.open();
this.shell.layout();
while (!this.shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
} finally {
Tray tray = Display.getDefault().getSystemTray();
if (tray != null) {
for (TrayItem item : tray.getItems()) {
item.dispose();
}
}
}
}
/**
* トレイアイコンを追加します
*
* @param display
* @return
*/
private TrayItem addTrayItem(final Display display) {
// トレイアイコンを追加します
Tray tray = display.getSystemTray();
TrayItem item = new TrayItem(tray, SWT.NONE);
Image image = display.getSystemImage(SWT.ICON_INFORMATION);
item.setImage(image);
item.setToolTipText(AppConstants.NAME + AppConstants.VERSION);
item.addListener(SWT.Selection, new TraySelectionListener(this.shell));
item.addMenuDetectListener(new TrayItemMenuListener(this.getShell()));
return item;
}
public Tray getSWT() {
return tray;
}