Switching out MenuBar – Part 2

Kevin had an interesting comment on my last blog that prompted me to write this note. First off, he gave me this suggestion to make it to work, which I think is cool.

JMenuBar newMenu = getNewMenuBar();
JFrame frame = appContext.getFrame();
frame.setJMenuBar( newMenu );

Also, he asked why I am creating multiple menu bars instead of re-creating the menu items when switching contexts. I thought about it for a while and came to the following conclusion. If you switch contexts frequently, pre-creating menu bars and switching out would be beneficial, especially in scenarios where context switches need to happen on mouse overs. On the other hand, if you do context switches once in a while, it doesn’t hurt to re-create the menu items on demand.

As a side note, I create my menu items from an XML file, using Castor. If anyone is interested, I would be happy to share the code.

2 Replies to “Switching out MenuBar – Part 2

  1. Hi,

    This post is quite old now, but I’m struggling with castor and my RCP application, so I’d be glad to see how you successfuly managed to make them work together

    My email is

    Thanks in advance.

Leave a Reply

Your email address will not be published. Required fields are marked *