Results 1 to 2 of 2

Thread: tray popup menu

  1. #1
    newbiejava is offline Senior Member
    Join Date
    Jan 2010
    Posts
    138
    Rep Power
    0

    Default tray popup menu

    I am new to java, I am trying create tray popup-menu, it works but the tray icon not shown.. :confused:
    I already put the .gif (16x16) into the same folder as the class files.


    public static void main(String[] args) {
    // TODO code application logic here
    if (!SystemTray.isSupported())
    {
    cls1.msgBox(null, "The system tray is not supported on the current platform.","Message", MESSAGE_INFO);
    }
    else
    {
    try{
    ImageIcon icon = new ImageIcon("action_go.gif");
    String tooltip ="Matrix Communicator";
    PopupMenu popupMenu = new PopupMenu();
    final TrayIcon trayIcon= new TrayIcon(icon.getImage(), tooltip, popupMenu);
    SystemTray sysTray= SystemTray.getSystemTray();

    ActionListener showPhoneUsage = new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    System.out.println("Exiting...");
    System.exit(0);
    }
    };

    ActionListener configurationListener = new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    System.out.println("Exiting...");
    System.exit(0);
    }
    };

    ActionListener exitListener = new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    System.out.println("Exiting...");
    System.exit(0);
    }
    };
    MenuItem jMenuItem1 = new MenuItem("Show Phone Usage");
    popupMenu.add(jMenuItem1);
    jMenuItem1.addActionListener(showPhoneUsage);
    popupMenu.addSeparator();
    MenuItem jMenuItem2 = new MenuItem("Configuration");
    popupMenu.add(jMenuItem2);
    jMenuItem2.addActionListener(configurationListener );
    popupMenu.addSeparator();
    MenuItem jMenuItem3 = new MenuItem("Exit");
    popupMenu.add(jMenuItem3);
    jMenuItem3.addActionListener(exitListener);
    sysTray.add(trayIcon);
    }
    catch (AWTException e){
    cls1.msgBox(null, e.toString(), "Error", MESSAGE_ERROR);
    }
    catch(Exception e){
    cls1.msgBox(null, e.toString(), "Error", MESSAGE_ERROR);
    }
    }
    }
    }

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,450
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by newbiejava View Post
    I am new to java, I am trying create tray popup-menu, it works but the tray icon not shown.. :confused:
    I already put the .gif (16x16) into the same folder as the class files.
    Java Code:
                 ImageIcon icon = new ImageIcon("action_go.gif");
    Try an absolute file path, e.g. c:/your/path/to/action_go.gif because your current working directory might not be what you think it is.

    kind regards,

    Jos
    Last edited by JosAH; 01-11-2010 at 07:05 PM. Reason: typo

Similar Threads

  1. js popup menu problem
    By webdreamer in forum New To Java
    Replies: 2
    Last Post: 11-16-2009, 08:50 PM
  2. How can I add popUp menu on a tab of a tabbedPane?
    By shahid0627 in forum AWT / Swing
    Replies: 1
    Last Post: 08-31-2009, 04:19 AM
  3. Regarding popup menu in netbeans IDE
    By santhosh_el in forum AWT / Swing
    Replies: 2
    Last Post: 03-11-2009, 01:14 PM
  4. Replies: 0
    Last Post: 07-25-2008, 02:32 PM
  5. Replies: 7
    Last Post: 05-09-2008, 07:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •