系统托盘图标,添加“单击此处”链接

时间:2012-07-25 13:52:57

标签: java system awt tray

我有以下代码打开窗口通知,但我希望“点击此处”的部分链接到文本文件。如何将此功能添加到trayicon?

public class foundDocs implements ActionListener {


public static void main(String[]args) throws AWTException
{
    new foundDocs();
}
foundDocs() throws AWTException 
   { 
       SystemTray tray = SystemTray.getSystemTray(); 
        java.awt.Image image = Toolkit.getDefaultToolkit().getImage("tray.gif"); 
        TrayIcon trayIcon = new TrayIcon(image, "Tray Demo"); 
        tray.add(trayIcon); 
        trayIcon.displayMessage("Found new document associations:", "Click here to view", MessageType.INFO); 
        trayIcon.addActionListener(this);
    }

@Override
public void actionPerformed(ActionEvent arg0) 
{
    // display the text file in the default app. 
    try {
        Desktop.getDesktop().open(new File("Users.txt"));
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } 

}

}

1 个答案:

答案 0 :(得分:2)

Add an ActionListenerTrayIcon。在活动中,请使用以下内容:

// display the text file in the default app.
Desktop.getDesktop().open(new File("the.txt"));