//点击关闭或者小化时程序不会退出而是显示到托盘中    当然也可以是显示在任务栏中的

  public class TrayApp {

  public static void main(String[] args) {

  Display display = new Display();

  final Shell shell = new Shell(display);

  shell.setText("小化到系?托?");

  //取消系?中??的??,????在托?不能?示

  shell.setImage(display.getSystemImage(SWT.ICON_INFORMATION));

  //?建系?托?

  final Tray tray = display.getSystemTray();

  final TrayItem trayItem = new TrayItem(tray, SWT.NONE);

  //?置在托?中?示的程序??

  trayItem.setImage(display.getSystemImage(SWT.ICON_INFORMATION));

  //程序???,窗口是?示的,所以托????藏

trayItem.setVisible(false);
trayItem.setToolTipText(shell.getText());
trayItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
toggleDisplay(shell, tray);
}
});
final Menu trayMenu = new Menu(shell, SWT.POP_UP);
MenuItem showMenuItem = new MenuItem(trayMenu, SWT.PUSH);
showMenuItem.setText("?示窗口(&s)");

  //?示窗口,并?藏托???

showMenuItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
toggleDisplay(shell, tray);
}
});
trayMenu.setDefaultItem(showMenuItem);
new MenuItem(trayMenu, SWT.SEPARATOR);

  //托?中的退出菜?,程式只能通???菜?退出

MenuItem exitMenuItem = new MenuItem(trayMenu, SWT.PUSH);
exitMenuItem.setText("退出程式(&x)");
exitMenuItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
shell.dispose();
}
});

  //在托?????鼠?右??的事件,?出系?菜?

trayItem.addMenuDetectListener(new MenuDetectListener() {
public void menuDetected(MenuDetectEvent e) {
trayMenu.setVisible(true);
}
});