I have always created MenuBars as follows.
class MyMenuBar extends JMenuBar { add(new FileItem()) } class FileItem extends MenuItem { addMenuItem(new ExitAction()) } class ExitAction extends AbstractAction {
then in your main frame you just add the JFrame myframe menu bar to it;
myFrame.setMenuBar(new MyMenuBar())
Some of these syntaxes may be incorrect if you did not write a menu at the time. You can extend it by adding factory classes that return your actions so that you can reuse them or use some DI frameworks to do the same.
source share