hi!

I add code example. when I run that, I get exceptions:

/*******************************************************************************
 * Copyright (c) 2000, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
//package org.eclipse.swt.snippets;
/*
 * Tray example snippet: place an icon with a popup menu on the system tray
 *
 * For a list of all SWT example snippets see
 * http://www.eclipse.org/swt/snippets/
 * 
 * @since 3.0
 */
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 SystemTrayIconPopup {

  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    Image image = new Image(display, "C:\\Users\\NLG\\workspace\\Watcher\\PNG_small\\Regular\\try.png");
    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);
      
  
      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();
  }
}

and the exception:

System.InvalidCastException: Unable to cast object of type 'System.Windows.Forms.NotifyIcon' to type 'System.Windows.DependencyObject'.
   at Java_org_eclipse_swt_internal_wpf_OS_NameScope_1SetNameScope(JNIEnv_* env, _jclass* that, Int32 arg0, Int32 arg1)
Java: 
java.lang.Exception: Stack trace
	at java.lang.Thread.dumpStack(Thread.java:1353)
	at org.eclipse.swt.internal.wpf.OS.NameScope_SetNameScope(Native Method)
	at org.eclipse.swt.widgets.Widget.setNameScope(Unknown Source)
	at org.eclipse.swt.widgets.Widget.createWidget(Unknown Source)
	at org.eclipse.swt.widgets.TrayItem.<init>(Unknown Source)
	at SystemTrayIconPopup.main(SystemTrayIconPopup.java:42)

I try to find a solution, but I failed...
If someone could help me - it will be great!
thanks,
-Nate

I copied your code, compiled and executed it without problems on a WinXP system with java 1.6.0-10

This looks like incompatibility between libraries, Java and Windows versions. Make sure you get versions of the products that match versions.

This looks like incompatibility between libraries, Java and Windows versions. Make sure you get versions of the products that match versions.

how can I check it?

could u tell me which libraries should I add?

this is a link to picture of my jars/libraries:

http://img444.imageshack.us/img444/215/libraries.jpg

thanks,
-Nate

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.