1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Tray;
import org.eclipse.swt.widgets.TrayItem;
import org.eclipse.swt.widgets.ToolTip;
import org.eclipse.swt.widgets.Shell;
public void createTray() {
final Display displayTray = new Display();
final Shell shellTray = new Shell(displayTray);
final Tray tray = displayTray.getSystemTray();
final ToolTip tipTray = new ToolTip(shellTray, SWT.BALLOON | SWT.ICON_INFORMATION);
tipTray.setText("Tray Title");
if (tray != null) {
final TrayItem item = new TrayItem(tray, SWT.NONE);
item.setToolTipText("Tooltip Title");
item.setImage(new Image(displayTray, getClass().getResourceAsStream("/projet/icon.png")));
item.setToolTip(tipTray);
item.setVisible(true);
tipTray.setMessage("Tooltip Text...");
// Fait disparaitre l'icône lorsque on clic dessus
item.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
shellTray.dispose();
}
});
}else{
// Tray icon not possible
}
tipTray.setVisible(true);
while (!shellTray.isDisposed()) {
if (!displayTray.readAndDispatch())
displayTray.sleep();
}
displayTray.dispose();
} |
Partager