title: OSX Swing: Dynamic com.apple.laf.ScreenMenuBar content configuration
body: <p>I have a cross-platform swing application with dynamic MenuBar content, eg. on every "File → Recent" menu open, there could be a completely different menu items list, depending on recent opened files.</p>
  
  <p>For <strong>Windows</strong> there is no problems with it, I've overridden <code>JMenu.setPopupMenuVisible(boolean)</code> method and I refresh my items list before <code>super.setPopupMenuVisible(b)</code> call.</p>
  
  <p>But for <strong>OSX</strong> I use system MenuBar which uses wrapper for all related components (wrapper clesses are ScreenMenuItem, ScreenMenu and ScreenMenuBar), so I do not receive any mouse events for my JMenu-components and cannot override any method.</p>
  
  <p>Any suggestions or workarounds?</p>
  
  <p><strong>SSCCE</strong></p>
  
  <pre><code>public class MenuBarTest {
      public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
              @Override
              public void run() {
                  start();
              }
          });
      }
  
      private static void start() {
          final JFrame frame = new JFrame();
          frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  
          JMenuBar menuBar = new JMenuBar();
  
          JMenu fileMenu = new JMenu("File");
          JMenu recent = new JMenu("Recent") {
              @Override
              public void setPopupMenuVisible(boolean b) {
                  removeAll();
  
                  Random r = new Random();
                  int amount = r.nextInt(5) + 1;
  
                  for (int i = 0; i &lt; amount; i++) {
                      add(new JMenuItem(String.valueOf(i + 1)));
                  }
  
                  super.setPopupMenuVisible(b);
              }
          };
  
          fileMenu.add(recent);
          menuBar.add(fileMenu);
  
          frame.setJMenuBar(menuBar);
  
          frame.setSize(200, 150);
          frame.setLocationRelativeTo(null);
  
          frame.setVisible(true);
      }
  }
  </code></pre>