TrayIcon!

7 respostas
J

Dae galera!! Tava dando uma testada na biblioteca JDIC (JDesktop Integration Components) (https://jdic.dev.java.net/), e achei um
exemplo na net, baixei e adicionei esse jar no eclipse jdic.jar, só que quando eu rodo esse exemplo, dá as seguintes mensagens:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no tray in java.library.path
	at java.lang.ClassLoader.loadLibrary(Unknown Source)
	at java.lang.Runtime.loadLibrary0(Unknown Source)
	at java.lang.System.loadLibrary(Unknown Source)
	at org.jdesktop.jdic.tray.internal.impl.DisplayThread.<clinit>(Unknown Source)
	at org.jdesktop.jdic.tray.internal.impl.WinSystemTrayService.<clinit>(Unknown Source)
	at org.jdesktop.jdic.tray.internal.impl.ServiceManagerStub.getService(Unknown Source)
	at org.jdesktop.jdic.tray.internal.ServiceManager.getService(Unknown Source)
	at org.jdesktop.jdic.tray.SystemTray.<clinit>(Unknown Source)
	at tray.TryTeste.<init>(TryTeste.java:38)
	at tray.TryTeste.main(TryTeste.java:43)
Exception in thread "Thread-2" java.lang.UnsatisfiedLinkError: removeIcon
	at org.jdesktop.jdic.tray.internal.impl.WinTrayIconService.removeIcon(Native Method)
	at org.jdesktop.jdic.tray.internal.impl.WinTrayIconService.removeAllIcons(Unknown Source)
	at org.jdesktop.jdic.tray.internal.impl.WinTrayIconService$1.run(Unknown Source)

O fonte que eu to usando é esse:

package tray.teste;

import java.awt.event.*;
import javax.swing.*;
import org.jdesktop.jdic.tray.TrayIcon;
import org.jdesktop.jdic.tray.SystemTray;


public class TrayTeste {
    public static JMenuItem quit;
    
    public TrayTeste() {
        JPopupMenu menu = new JPopupMenu("Tray Icon Menu");
        menu.add(new JMenuItem("Test Item"));
        menu.addSeparator();
        JMenuItem quitItem = new JMenuItem("Quit");
        quitItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                System.exit(0);
            }});
        menu.add(quitItem);
        
        // O arquivo “devmedia.gif” deve existir no mesmo diretório

        // onde estiver esta classe.
        ImageIcon icon = new ImageIcon("eletric.gif");
        TrayIcon ti = new TrayIcon(icon, "JDIC Tray Icon API Test", menu);

        // Ação para clique com botão esquerdo.
        ti.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(null, 
                    "JDIC Tray Icon API Test!", "About",
                    JOptionPane.INFORMATION_MESSAGE);
            }
        });
               
        SystemTray tray = SystemTray.getDefaultSystemTray();
        tray.addTrayIcon(ti);
    }

    public static void main(String[] args) {
        new TrayTeste();
    }   
}

Alguém sabe do que se trata?
Valeu!!!

7 Respostas

L

eu tinha esse problema tb…
vc tem q colocar o tray.dll na mesma pasta do tray.jar…
dai funciona…

Dassayev

Estou com um problema com o Windows 7 64 bits. Está sendo gerado o seguinte erro:

Exception in thread "main" java.lang.UnsatisfiedLinkError: D:\Sistemas\Java\Projetos\Projetos NetBeans\FTP\tray.dll: Can't load IA 32-bit .dll on a AMD 64-bit platform at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1778) at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1703) at java.lang.Runtime.loadLibrary0(Runtime.java:823) at java.lang.System.loadLibrary(System.java:1028) at org.jdesktop.jdic.tray.internal.impl.DisplayThread.<clinit>(Unknown Source) at org.jdesktop.jdic.tray.internal.impl.WinSystemTrayService.<clinit>(Unknown Source) at org.jdesktop.jdic.tray.internal.impl.ServiceManagerStub.getService(Unknown Source) at org.jdesktop.jdic.tray.internal.ServiceManager.getService(Unknown Source) at org.jdesktop.jdic.tray.SystemTray.<clinit>(Unknown Source) at br.com.jdsistemas.ftp.IconeTray.exibir(IconeTray.java:81) at br.com.jdsistemas.ftp.FTP.main(FTP.java:34) Exception in thread "Thread-2" java.lang.UnsatisfiedLinkError: org.jdesktop.jdic.tray.internal.impl.WinTrayIconService.removeIcon(I)V at org.jdesktop.jdic.tray.internal.impl.WinTrayIconService.removeIcon(Native Method) at org.jdesktop.jdic.tray.internal.impl.WinTrayIconService.removeAllIcons(Unknown Source) at org.jdesktop.jdic.tray.internal.impl.WinTrayIconService$1.run(Unknown Source) Java Result: 1

No windows 7 32 bits funcionava normal.

O_Monge

Desculpa a ignorância, mas por que estás usando o TrayIcon do pacote org.jdesktop.jdic.tray e não o do java.awt?

Eu já usei também o trayicon que infelizmente é incompatível com o swing, apenas com awt. Fica feio no linux, mas no windows fica quase normal..

Pra usar o swing, existe uma gambi:
trayIcon.addMouseListener(new MouseAdapter() {
			boolean isVisible = false;
			
			public void mouseReleased(MouseEvent e) {
				if(e.isPopupTrigger()) {
					menu.setVisible(false);
				}
			}
			public void mousePressed(MouseEvent e) {
				if ( isVisible ) {
					getMenu().setVisible(false);
					isVisible = false;
				} else {
					getMenu().setInvoker(getMenu());
					getMenu().setLocation(e.getX(), e.getY());
					getMenu().setVisible(true);
					isVisible = true;
				}
			}
		});
Dassayev

Blz. Funcionou com o AWT mas a imagem no Tray não aparece.

Dassayev

Funcionou cara!!! O lance da imagem era o tamanho dela!
Valeu parceiro!!!

G

ei, posta o codigo ai com um exemplo que eu quero usar esse troço ai tb!

Como e que isso funciona? so com o awt?? Tem como mandar um exemplo pequeninho ai? Foi mal por ja ir pedindo assim, mas acho que isso deve ser facinho de fazer e como tu ja fez, custa nada, ne?

hehehe Valeu!

Dassayev
Minha classe ficou assim:
public class IconeTray {

    public void exibir() {
        try {
            //ImageIcon icon = new ImageIcon(getClass().getResource("/br/com/jdsistemas/imagens/logo.png"));
            ImageIcon icon = new ImageIcon(getClass().getResource("/jdbackup/images/logo_tray.png"));

            PopupMenu menu = new PopupMenu("JD Backup");

            MenuItem quitItem = new MenuItem("Fechar");
            quitItem.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent evt) {
                    if (Messages.confirm("Fechar o sistema?")) {
                        System.exit(0);
                    }
                }
            });

            MenuItem openItem = new MenuItem("Abrir");
            openItem.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent evt) {
                    try {
                        FrameInicial.getInstance().setVisible(true);
                    } catch (ParseException ex) {
                        Messages.error("", ex);
                    }
                }
            });

            MenuItem sobreItem = new MenuItem("Sobre");
            sobreItem.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent evt) {
                    try {
                        DialogSobre.getInstance().setVisible(true);
                    } catch (ParseException e) {
                        Messages.error("", e);
                    }
                }
            });

            menu.add(openItem);
            menu.add(sobreItem);
            menu.add(quitItem);

            TrayIcon ti = new TrayIcon(icon.getImage(), "JD Backup", menu);
            //ti.setIconAutoSize(true);

            // Ação para clique com botão esquerdo.
            ti.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    try {
                        FrameInicial.getInstance().setVisible(true);
                    } catch (ParseException ex) {
                        Messages.error("", ex);
                    }
                }
            });

            SystemTray tray = SystemTray.getSystemTray();
            tray.add(ti);
        } catch (Exception ex) {
            ex.printStackTrace();
            Logger.getLogger(IconeTray.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
}

Um abraço!

Criado 23 de outubro de 2006
Ultima resposta 28 de abr. de 2011
Respostas 7
Participantes 5