I thought it was the order they were added but for some odd reason, the "Exit" item appears above the submenu. Here is my code:
gram._ni.setPopupMenu(new PopupMenu());
gram._ni.getPopupMenu().add("Re-Read");
gram._ni.getPopupMenu().add("Pronunciations");
gram._ni.getPopupMenu().add("Pause");
gram._ni.getPopupMenu().add("Stop");
gram._ni.getPopupMenu().add(gram._voiceMenu);
gram._ni.getPopupMenu().add("Exit");
_ni is a TrayIcon. (used to be a "NotifyIcon" when this was a C#.Net program) gram is an instance of the "Program" class that contains my main method.
vcr says ha can not reproduce this problem, so here is my system info:
OpenJDK version "1.8.0_121" OpenJDK Runtime Environment (build 1.8.0_121-b14) OpenJDK 64-Bit Server VM (build 25.121-b14, mixed mode) Fedora Core 24, kernel 4.9.13-100.fc24.x86_64 Xfce 4.12
It turns out I had another one of these later in my code:
gram._ni.getPopupMenu().add(gram._voiceMenu);
I did not notice since, adding the same object will move the object rather than add a duplicate.