Results 1 to 7 of 7
  1. #1
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default [SOLVED] Windows Linux conflict - TrayIcon image not display in Linux

    Hi all,

    I have create a TrayIcon and then add image and a pop-up menu into it as follows.

    Java Code:
    public void trayIconEventHandling()
        {
            TrayIcon trayIcon;
     
            if (SystemTray.isSupported()){
                SystemTray tray = SystemTray.getSystemTray();
                
             // I have to use this ActionEvent to exit the dialog as well
             // Exit from the complete application
                ActionListener exitListener = new ActionListener(){
                    public void actionPerformed(ActionEvent e){
                        System.out.println("Exiting...");
                        System.exit(0);
                    }
                };
                
            // Open the dialog in Actionevent
                ActionListener openDialogListner = new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        System.out.println("Open another Dialog here.");
                        new AboutWindow().setVisible(true);
                    }
                };
                
            // Tray icon menu implimenting goes here
                PopupMenu popup = new PopupMenu();
                MenuItem defaultItem = new MenuItem("Exit");
                MenuItem openDlgItem = new MenuItem("About");
                MenuItem extartItem = new MenuItem("Others...");
                
                openDlgItem.setEnabled(false);
                
                defaultItem.addActionListener(exitListener);
                openDlgItem.addActionListener(openDialogListner);
                
                popup.add(defaultItem);
                popup.add(openDlgItem);
                popup.addSeparator();
                popup.add(extartItem);
     
                Image image = Toolkit.getDefaultToolkit().getImage("mytrayicon/RADAR.gif");
                trayIcon = new TrayIcon(image, "Pop-up", popup);
     
                ActionListener actionListener = new ActionListener(){
                    public void actionPerformed(ActionEvent e){    
                        System.out.println("Main Dialog!");
     
                    // Try to simply call the GUI here
                        mainWnd.setVisible(true);
                    }
                };
                trayIcon.setImageAutoSize(true);
                trayIcon.addActionListener(actionListener);
                trayIcon.addMouseListener(mouseListener);
     
                try
                {
                    tray.add(trayIcon);
                } 
                catch (AWTException e) 
                {
                    System.err.println("TrayIcon could not be added.");
                }
            } 
            else{
                System.err.println("System tray is currently not supported.");
            }   
        }
    My code working well on Windows, loaded the image correctly. But in Linux it don't.

    As far as I know about Java, I believe my code is correct. Then why this is happened on Linux. Somebody can give me a hint that where I'm going wrong.

    Important thing here is, Linux does not give any exception also. :(

    Eranga
    Last edited by Eranga; 03-25-2008 at 05:41 AM. Reason: adding more

  2. #2
    Anachron is offline Member
    Join Date
    Jan 2009
    Posts
    2
    Rep Power
    0

    Default

    Eranga, please give some more details.
    What desktop/window manager do you use (I just have tested similar code in KDE 3.5.10 and anything gone well) and what Linux distribution it is?
    Also, it would be very useful to know what's the version of Java your application is running on, both in Windows and in Linux.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    This is very old thread I've started. Actually the conflict there is not with the coding.

    I'm working on the KDE 3.5 as well, with the JDK version 1.6 and I don't remember the minor version of it. I've use the latest at that time.

    I've found two reasons effected on this,
    1. Image size limitation, I cannot use an image around more than 2MB
    2. *.gif types are not supported. *.png used

  4. #4
    Anachron is offline Member
    Join Date
    Jan 2009
    Posts
    2
    Rep Power
    0

    Default

    Eranga, thanks!
    You've just saved us (I mean the forum members) some hours of investigation :)

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  6. #6
    asesor is offline Member
    Join Date
    Apr 2009
    Posts
    3
    Rep Power
    0

    Default

    Eranga, i was looking your code, was missing the main, a package mainWnd
    and the method AboutWindow(), after that i had problems with a mouselistener but i think it is related with the first error. So i couldnt make it works.

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Actually that's a part of an application. There is no main method, it's only about the tray icon handling. What you want to do is, write a simple class and call this method in appropriate place.

Similar Threads

  1. open a pdf file in linux
    By aparna in forum Advanced Java
    Replies: 5
    Last Post: 06-08-2010, 12:51 PM
  2. new member need help with linux
    By praveena in forum New To Java
    Replies: 0
    Last Post: 01-22-2008, 10:22 AM
  3. problem with ServerSocket on Linux
    By gabriel in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 04:46 PM
  4. eclipse in linux
    By bbq in forum Eclipse
    Replies: 1
    Last Post: 07-04-2007, 08:59 AM
  5. Linux and java
    By Alan in forum Advanced Java
    Replies: 2
    Last Post: 05-31-2007, 02:30 PM

Posting Permissions

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