Results 1 to 2 of 2
  1. #1
    Kenan89 is offline Member
    Join Date
    Dec 2009
    Posts
    3
    Rep Power
    0

    Default minimize button and system tray

    Hello

    When i push the minimize button i would like to do a

    Java Code:
    myFrame.setState ( Frame.ICONIFIED );
    but the question is, where do i write this?

    also, i would like my application the go to system tray:

    Java Code:
       public void systemTray() {
            if (SystemTray.isSupported()) {
                SystemTray tray = SystemTray.getSystemTray();
                Image image = Toolkit.getDefaultToolkit().getImage("sdu.gif");
    
    
                ActionListener exitListener = new ActionListener() {
    
                    public void actionPerformed(ActionEvent e) {
                        System.out.println("Exiting...");
                        System.exit(0);
                    }
                };
    
    
                PopupMenu popup = new PopupMenu();
                MenuItem defaultItem = new MenuItem("Exit");
                defaultItem.addActionListener(exitListener);
                popup.add(defaultItem);
    
                trayIcon = new TrayIcon(image, "Tray Demo", popup);
                trayIcon.setImageAutoSize(true);
    
                try {
                    tray.add(trayIcon);
                } catch (AWTException e) {
                    System.err.println("TrayIcon could not be added.");
                }
    
            }
        }
    but when i put the method in the main method, is says:

    non-static method systemTray() cannot be referenced from a static contex

    How do i fix this? thanks! :)

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    you would need to create an instance of the class containing the method, inside your main() and then invoke methodInstance.systemTray(), or, make this test method static.

Similar Threads

  1. Replies: 6
    Last Post: 11-22-2010, 11:55 AM
  2. Minimize to System Tray In Windows
    By shapeshifter in forum AWT / Swing
    Replies: 4
    Last Post: 12-07-2008, 01:42 PM
  3. System Tray Message tracking.
    By Hichhiker in forum AWT / Swing
    Replies: 2
    Last Post: 10-11-2008, 03:58 AM
  4. Replies: 0
    Last Post: 07-25-2008, 02:32 PM
  5. System Tray
    By JavaLerner in forum New To Java
    Replies: 2
    Last Post: 07-13-2008, 08:25 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
  •