I was having a stupid problem when trying to switch out JMenuBar in a Swing app. The use case is like this. Initially, when the app is started, it displays a single File->Login.. menu. After the user logs in, depending on the role, the menu structure should change. You would think the following will work:
JFrame frame = appContext.getFrame();
frame.setJMenuBar( newMenu );
However, this was causing the app to hang arbitrarily. I tried setting the menu bar to null before setting the new one, tried removing the old one, tried to call invalidate() on JFrame, but no luck. Turns out that our old friend validate() needs to be invoked on the JFrame to get rid of the problem. I have been bitten by this problem before but it is so easy to miss. Thanks to Google and this site, I was able to solve it.
Finally, this worked: