这是一个已知问题。有一个错误报告,其中包含解决方法的大纲。我在下面进行了调整:
// Build your popup menu
final JPopupMenu trayPopup = new JPopupMenu();
// I'm using actions, there are other ways of doing this.
trayPopup.add(someFantaticAction);
// Get your tray icon
trayIcon = new TrayIcon(icon, "My awesome application");
trayIcon.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
maybeShowPopup(e);
}
@Override
public void mousePressed(MouseEvent e) {
maybeShowPopup(e);
}
private void maybeShowPopup(MouseEvent e) {
if (e.isPopupTrigger()) {
trayPopup.setLocation(e.getX(), e.getY());
trayPopup.setInvoker(trayPopup);
trayPopup.setVisible(true);
}
}
});