Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8342009

Tray Icon does not work on the latest Ubuntu 24.10 and KDE 6.6 in general

XMLWordPrintable

    • x86_64
    • linux_ubuntu

      ADDITIONAL SYSTEM INFORMATION :
      Ubuntu 24.10 and KDE 6.6 in general

      A DESCRIPTION OF THE PROBLEM :
      Tray Icon stopped working on Ubuntu 24.10 and on every distros that bundles KDE 6.6 more in general.
      TrayIcon is added to the traybar but the mouse listener does not work so no way to listen for a click on it making it unusable.




      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Just try to create a tray icon and listen for a mouse button on it. Code samples below.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Mouse event on the tray icon should trigger the listener but nothing happen.
      ACTUAL -
      If I click the tray icon, nothing happen.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.awt.event.*;

      public class TrayIconExample {

          public static void main(String[] args) {
              // Create a new tray icon
              SystemTray tray = SystemTray.getSystemTray();
              Image image = Toolkit.getDefaultToolkit().getImage("path/to/your/icon.png"); // Replace with the path to your image
              PopupMenu popup = new PopupMenu();
              MenuItem exitItem = new MenuItem("Exit");
              popup.add(exitItem);

              TrayIcon trayIcon = new TrayIcon(image, "My Tray Icon", popup);
              try {
                  tray.add(trayIcon);
              } catch (AWTException e) {
                  System.out.println("Error: tray icon not supported");
                  System.exit(1);
              }

              // Add a mouse listener
              trayIcon.addMouseListener(new MouseAdapter() {
                  @Override
                  public void mouseClicked(MouseEvent e) {
                      if (e.getButton() == MouseEvent.BUTTON1) {
                          System.out.println("Left button clicked");
                      } else if (e.getButton() == MouseEvent.BUTTON2) {
                          System.out.println("Middle button clicked");
                      } else if (e.getButton() == MouseEvent.BUTTON3) {
                          System.out.println("Right button clicked");

                      }
                  }
              });

              // Add a listener for the exit event
              exitItem.addActionListener(e -> System.exit(0));

              // Main loop to keep the application running
              while (true) {
                  try {
                      Thread.sleep(1000); // Check every second
                  } catch (InterruptedException ex) {
                      // Handle the interruption
                  }
              }
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      no workaround found. blocking issue.

      FREQUENCY : always


            azvegint Alexander Zvegintsev
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: