Home Tray Icon Opening Behind System Tray
Reply: 0

Tray Icon Opening Behind System Tray

user2707
1#
user2707 Published in June 20, 2018, 12:14 am

I have a simple Java application that sets a reminder and displays a message on the System Tray when the timer ends. When the user starts the program, a GUI is displayed that takes the user's inputs and then its minimized to the System Tray and the user can right click it and select "Options" or "Exit".

The Problem: When using Linux, the user right clicks on the Tray Icon and the menu opens up behind the System Tray meaning the user can not access "Options" or "Exit" and also, the "timer end" notification opens behind the System Tray.

How do I bring the menu and the notifications to the front?

private void initSystemTray() {
    //Declare the variables and the menus
    popup.add(menu1);
    popup.addSeparator();
    popup.add(exitItem);

    menu1.add(optionItem);

    trayIcon.setPopupMenu(popup);

    try {
        tray.add(trayIcon);
    }
    catch (Exception e) {

    }

}

public ReminderGUI() {

   if (SystemTray.isSupported()) {

       initSystemTray(); 
    //When the exit item is selected it closes the entire program
    exitItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            System.exit(0);
        }
    });

    //Displays the GUI to change the reminder settings
    optionItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            tray.remove(trayIcon);
            ReminderGUI myGUI = new ReminderGUI();
            myGUI.setVisible(true);
        }
    });

    menu1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            menu1.setEnabled(true);
        }
}); 
}               
}        

private void startJButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             

    String message;

    //Gets the reminder message inputed in the text area
    message = notificationJTextField.getText();

    //Timer task is created
    TimerTask timerTask = new TimerTask() {
    public void run() {
      timePassed++;
      //3600 seconds is one hour
      if (timePassed >= 3600) {       
         timerEnd = true;
         hourTimer.cancel();  
      }
      //When timer is done it displays the reminder message
      if (timerEnd) {
         trayIcon.displayMessage("End Timer", message, 
         TrayIcon.MessageType.INFO);

         timePassed = 0;
         timerEnd = false;

      }
    }
};
//If the 5 minutes reminder option is selected it shows the reminder message
// after 5 minutes

if (remindJComboBox.getSelectedItem() == "5 Minutes") {
        hourTimer.schedule(timerTask, 0, 83);
    }
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.308305 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO