//????????
shell.addShellListener(new ShellAdapter() {
//??????С?????????????????????????
public void shellIconified(ShellEvent e) {
toggleDisplay(shell?? tray);
}
//???????????????????????????????????????????
public void shellClosed(ShellEvent e) {
e.doit = false; //?????????
toggleDisplay(shell?? tray);
}
});
shell.setSize(320?? 240);
center(shell);
shell.open();
while(!shell.isDisposed()) {
if(!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
/**
* ????????????????????????????????????
* ?????????????????????????????????
*/
private static void toggleDisplay(Shell shell?? Tray tray) {
try {
shell.setVisible(!shell.isVisible());           //?????????
tray.getItem(0).setVisible(!shell.isVisible()); //???????????
//?????????????
if(shell.getVisible()) {
shell.setMinimized(false);  //???????С??
shell.setActive();          //??????
}
} catch(Exception e) {
e.printStackTrace();
}
}
/**
* ?????????
*/
private static void center(Shell shell) {
Monitor monitor = shell.getMonitor();
Rectangle bounds = monitor.getBounds();
Rectangle rect = shell.getBounds();
int x = bounds.x + (bounds.width - rect.width)/2;
int y = bounds.y + (bounds.height - rect.height)/2;
shell.setLocation(x?? y);
}
}