Example usage for org.eclipse.swt.widgets Display getSystemTray

List of usage examples for org.eclipse.swt.widgets Display getSystemTray

Introduction

In this page you can find the example usage for org.eclipse.swt.widgets Display getSystemTray.

Prototype

public Tray getSystemTray() 

Source Link

Document

Returns the single instance of the system tray or null when there is no system tray available for the platform.

Usage

From source file:Snippet143.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    Image image = new Image(display, 16, 16);
    final Tray tray = display.getSystemTray();
    if (tray == null) {
        System.out.println("The system tray is not available");
    } else {/*from ww  w.  j a va2 s .com*/
        final TrayItem item = new TrayItem(tray, SWT.NONE);
        item.setToolTipText("SWT TrayItem");
        item.addListener(SWT.Show, new Listener() {
            public void handleEvent(Event event) {
                System.out.println("show");
            }
        });
        item.addListener(SWT.Hide, new Listener() {
            public void handleEvent(Event event) {
                System.out.println("hide");
            }
        });
        item.addListener(SWT.Selection, new Listener() {
            public void handleEvent(Event event) {
                System.out.println("selection");
            }
        });
        item.addListener(SWT.DefaultSelection, new Listener() {
            public void handleEvent(Event event) {
                System.out.println("default selection");
            }
        });
        final Menu menu = new Menu(shell, SWT.POP_UP);
        for (int i = 0; i < 8; i++) {
            MenuItem mi = new MenuItem(menu, SWT.PUSH);
            mi.setText("Item" + i);
        }
        item.addListener(SWT.MenuDetect, new Listener() {
            public void handleEvent(Event event) {
                menu.setVisible(true);
            }
        });
        item.setImage(image);
    }
    shell.setBounds(50, 50, 300, 200);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    image.dispose();
    display.dispose();
}

From source file:SystemTrayIconPopup.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    Image image = new Image(display, 16, 16);
    final Tray tray = display.getSystemTray();
    if (tray == null) {
        System.out.println("The system tray is not available");
    } else {/*from   w ww  .  ja  v  a2 s. c om*/
        final TrayItem item = new TrayItem(tray, SWT.NONE);
        item.setToolTipText("SWT TrayItem");
        item.addListener(SWT.Show, new Listener() {
            public void handleEvent(Event event) {
                System.out.println("show");
            }
        });
        item.addListener(SWT.Hide, new Listener() {
            public void handleEvent(Event event) {
                System.out.println("hide");
            }
        });
        item.addListener(SWT.Selection, new Listener() {
            public void handleEvent(Event event) {
                System.out.println("selection");
            }
        });
        item.addListener(SWT.DefaultSelection, new Listener() {
            public void handleEvent(Event event) {
                System.out.println("default selection");
            }
        });
        final Menu menu = new Menu(shell, SWT.POP_UP);
        for (int i = 0; i < 8; i++) {
            MenuItem mi = new MenuItem(menu, SWT.PUSH);
            mi.setText("Item" + i);
            mi.addListener(SWT.Selection, new Listener() {
                public void handleEvent(Event event) {
                    System.out.println("selection " + event.widget);
                }
            });
            if (i == 0)
                menu.setDefaultItem(mi);
        }
        item.addListener(SWT.MenuDetect, new Listener() {
            public void handleEvent(Event event) {
                menu.setVisible(true);
            }
        });
        item.setImage(image);
    }
    //  shell.setBounds(50, 50, 300, 200);
    //    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    image.dispose();
    display.dispose();
}

From source file:ToolTipBalloon.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    Image image = null;/*from   w ww . j ava2s .c o  m*/
    final ToolTip tip = new ToolTip(shell, SWT.BALLOON | SWT.ICON_INFORMATION);
    tip.setMessage(
            "Here is a message for the user. When the message is too long it wraps. I should say something cool but nothing comes to my mind.");
    Tray tray = display.getSystemTray();
    if (tray != null) {
        TrayItem item = new TrayItem(tray, SWT.NONE);
        image = new Image(display, "yourFile.gif");
        item.setImage(image);
        tip.setText("Notification from a tray item");
        item.setToolTip(tip);
    } else {
        tip.setText("Notification from anywhere");
        tip.setLocation(400, 400);
    }
    Button button = new Button(shell, SWT.PUSH);
    button.setText("Press for balloon tip");
    button.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            tip.setVisible(true);
        }
    });
    button.pack();
    shell.setBounds(50, 50, 300, 200);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    if (image != null)
        image.dispose();
    display.dispose();
}

From source file:org.eclipse.swt.snippets.Snippet225.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 225");
    Image image = null;//from w  ww.j a v a2  s.  c o m
    final ToolTip tip = new ToolTip(shell, SWT.BALLOON | SWT.ICON_INFORMATION);
    tip.setMessage(
            "Here is a message for the user. When the message is too long it wraps. I should say something cool but nothing comes to my mind.");
    Tray tray = display.getSystemTray();
    if (tray != null) {
        TrayItem item = new TrayItem(tray, SWT.NONE);
        image = display.getSystemImage(SWT.ICON_INFORMATION);
        item.setImage(image);
        tip.setText("Notification from a tray item");
        item.setToolTip(tip);
    } else {
        tip.setText("Notification from anywhere");
        tip.setLocation(400, 400);
    }
    Button button = new Button(shell, SWT.PUSH);
    button.setText("Press for balloon tip");
    button.addListener(SWT.Selection, event -> tip.setVisible(true));
    Rectangle clientArea = shell.getClientArea();
    button.setLocation(clientArea.x, clientArea.y);
    button.pack();
    shell.setBounds(50, 50, 300, 200);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    if (image != null)
        image.dispose();
    display.dispose();
}

From source file:org.eclipse.swt.snippets.Snippet143.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 143");
    Image image = new Image(display, 16, 16);
    Image image2 = new Image(display, 16, 16);
    GC gc = new GC(image2);
    gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
    gc.fillRectangle(image2.getBounds());
    gc.dispose();/* w w w.j av a 2 s.c o m*/
    final Tray tray = display.getSystemTray();
    if (tray == null) {
        System.out.println("The system tray is not available");
    } else {
        final TrayItem item = new TrayItem(tray, SWT.NONE);
        item.setToolTipText("SWT TrayItem");
        item.addListener(SWT.Show, event -> System.out.println("show"));
        item.addListener(SWT.Hide, event -> System.out.println("hide"));
        item.addListener(SWT.Selection, event -> System.out.println("selection"));
        item.addListener(SWT.DefaultSelection, event -> System.out.println("default selection"));
        final Menu menu = new Menu(shell, SWT.POP_UP);
        for (int i = 0; i < 8; i++) {
            MenuItem mi = new MenuItem(menu, SWT.PUSH);
            mi.setText("Item" + i);
            mi.addListener(SWT.Selection, event -> System.out.println("selection " + event.widget));
            if (i == 0)
                menu.setDefaultItem(mi);
        }
        item.addListener(SWT.MenuDetect, event -> menu.setVisible(true));
        item.setImage(image2);
        item.setHighlightImage(image);
    }
    shell.setBounds(50, 50, 300, 200);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    image.dispose();
    image2.dispose();
    display.dispose();
}