下面列出了怎么用org.eclipse.swt.widgets.TrayItem的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 void removeTray(){
if (this.tray != null) {
setVisible(true);
TrayItem items[] = this.tray.getItems();
for(int i = 0; i < items.length; i ++){
items[i].dispose();
}
this.menu.dispose();
}
}
public TrayItemSWT(TrayDelegate tray, int style) {
item = new TrayItem(((TraySWT) tray).getSWT(), style);
}
/**
* @return トレイアイコン
*/
public TrayItem getTrayItem() {
return this.trayItem;
}
public void setItem(TrayItem item){
this.item = item;
}