Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-25-2008, 02:32 PM
Java Tip's Avatar
Moderator
 
Join Date: Nov 2007
Posts: 1,681
Rep Power: 4
Java Tip will become famous soon enoughJava Tip will become famous soon enough
Default Placing an icon with a popup menu on the system tray
Code:
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.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tray;
import org.eclipse.swt.widgets.TrayItem;

public class Snippet143 {

  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 {
      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();
  }
}
__________________
"The sole cause of man’s unhappiness is that he does not know how to stay quietly in his room." - Blaise Pascal
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to create Popup Menu with Sub Menu while right-clicking the JTree Node?? Kabiraa AWT / Swing 8 07-03-2009 05:41 AM
Minimize to System Tray In Windows shapeshifter AWT / Swing 4 12-07-2008 01:42 PM
System Tray JavaLerner New To Java 2 07-13-2008 08:25 AM
Fill a menu dynamically when menu is shown Java Tip SWT 0 07-07-2008 04:47 PM
[SOLVED] Baloon message on a tray icon Eranga AWT / Swing 5 04-10-2008 02:12 PM


All times are GMT +2. The time now is 12:11 AM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org