Results 1 to 10 of 10
  1. #1
    lepetitprince is offline Member
    Join Date
    Apr 2008
    Posts
    4
    Rep Power
    0

    Question [SOLVED] Problem with setVisible(); on LINUX

    Hello,

    Could anyone please tell me why the following code does not work on LINUX but on WINDOWS and what I could do to make it work? I have tried so many workarounds but nothing really worked out, I cannot get it visible again - at least not properly! Thank you in advance!

    Java Code:
     private void formWindowIconified(java.awt.event.WindowEvent evt) {                                     
    
            [COLOR="Red"]setVisible(false);[/COLOR]
            
        }                                    
        
        public void SysTray () {
            
                final TrayIcon trayIcon;
    
                if (SystemTray.isSupported()) {
    
                    SystemTray tray = SystemTray.getSystemTray();
                    java.net.URL iconUrl = this.getClass().getResource("jack_in_box.gif");
                    Image image = getToolkit().getImage(iconUrl);
    
                    MouseListener mouseListener = new MouseListener() {
    
                        public void mouseClicked(MouseEvent e) {
                            [COLOR="Red"]setVisible(true);
                            setExtendedState(Frame.NORMAL);[/COLOR]
                       }
    
                        public void mouseEntered(MouseEvent e) {
    
                        }
    
                        public void mouseExited(MouseEvent e) {
    
                        }
    
                        public void mousePressed(MouseEvent e) {
    
                        }
    
                        public void mouseReleased(MouseEvent e) {
    
                        }
                    };
    
                    ActionListener exitListener = new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            System.exit(0);
                        }
                    };
    
                    PopupMenu popup = new PopupMenu();
                    MenuItem defaultItem = new MenuItem("Exit");
                    defaultItem.addActionListener(exitListener);
                    popup.add(defaultItem);
    
                    trayIcon = new TrayIcon(image, "CheckInBox", popup);
    
                    trayIcon.setImageAutoSize(true);
                    trayIcon.addMouseListener(mouseListener);
                    
                    try {
                        tray.add(trayIcon);
                    } catch (AWTException e) {
                        System.err.println("TrayIcon could not be added.");
                    }
                    
                } else {
    
                    //  System Tray is not supported
    
                }
            
        }

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

    Default

    I think you use JFrame form in a IDE? So use a reference to the current object.

    Java Code:
    this.setVisible(false);
    Should work.

  3. #3
    lepetitprince is offline Member
    Join Date
    Apr 2008
    Posts
    4
    Rep Power
    0

    Default

    Hi Eranga,

    Thanks for the quick reply, but the problem is not the reference, the problem is that setVisible(true); in the MouseEvent does not set the JFrame visible again. It just -sometimes- blinks very fast in the panel (Task Bar), looses the focus and stays invisible. Only after I click it a couple of times I get it on the screen again. Oddly enough, it works fine on Windows. Maybe a "paint" problem?!

    Thank you for further help

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

  5. #5
    lepetitprince is offline Member
    Join Date
    Apr 2008
    Posts
    4
    Rep Power
    0

    Default

    I've just tried that - no success. Any other ideas?

  6. #6
    lepetitprince is offline Member
    Join Date
    Apr 2008
    Posts
    4
    Rep Power
    0

    Default

    I think I have to accept that it just do not work on Linux (Gnome).

    Thank you all anyway!

  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
    20

    Default

    I don't think it;s a good idea at all. Better to try different thing there. As much as possible try to get the exceptions and see what it mean. You may have a solution.

    Did you try it on formWindowOpened(). If so what happened there.

  8. #8
    DwD
    DwD is offline Member
    Join Date
    Nov 2008
    Posts
    2
    Rep Power
    0

    Default

    I solved this problem by a dirty workaround
    PHP Code:
        private void miniIt() {
            if (guiFrame.isVisible()) {
                guiFrame.setVisible(false);
            } else {
                //Gnome TrayIcon WorkAround
                guiFrame.setState(JFrame.NORMAL);
                guiFrame.setVisible(true);
                guiFrame.setState(JFrame.ICONIFIED);
                guiFrame.setVisible(false);
                guiFrame.setState(JFrame.NORMAL);
                guiFrame.setVisible(true);
            }
    
        }
    by DwD from jDownloader.org
    Last edited by DwD; 11-24-2008 at 01:43 PM.

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

  10. #10
    DwD
    DwD is offline Member
    Join Date
    Nov 2008
    Posts
    2
    Rep Power
    0

    Default

    Thats the reason why i call it dirty workaround.
    I think the problem is a missing notification if you minimize from the taskbar, thats the reason after
    guiFrame.setState(JFrame.NORMAL);
    guiFrame.setVisible(true);
    the gui is just visible in the panel
    after setting the gui state JFrame.ICONIFIED java know the program is iconfied but setVisible(true) if the frame is visible don't have any effect so you have to set visible false first. With JFrame.NORMAL you can restore a iconfied frame. Finaly you have to set visible true.

Similar Threads

  1. Replies: 6
    Last Post: 04-08-2009, 05:05 AM
  2. [SOLVED] alignment problem
    By nanimtech in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 04-10-2008, 02:23 PM
  3. [SOLVED] Actionevent problem
    By Cymro in forum New To Java
    Replies: 3
    Last Post: 04-04-2008, 08:11 AM
  4. Problem locating resources on Linux.
    By jimm1 in forum New To Java
    Replies: 1
    Last Post: 01-18-2008, 07:34 PM
  5. problem with ServerSocket on Linux
    By gabriel in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 05:46 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
  •