// -*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
// @homepage@

package example;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.WindowEvent;
import java.util.stream.Stream;
import javax.swing.*;
import javax.swing.plaf.basic.BasicToolBarUI;

public final class MainPanel extends JPanel {
  private MainPanel() {
    super(new BorderLayout());
    JPopupMenu popup = new JPopupMenu();
    initMenu(popup);

    JMenuBar bar = new JMenuBar();
    JMenu menu = new JMenu("File");
    initMenu(menu);
    bar.add(menu);

    JToolBar toolBar = new JToolBar();
    toolBar.add(new JLabel("Floatable JToolBar:"));
    toolBar.add(Box.createGlue());
    toolBar.add(new ExitAction());

    JTree tree = new JTree();
    tree.setComponentPopupMenu(popup);
    add(bar, BorderLayout.NORTH);
    add(new JScrollPane(tree));
    add(toolBar, BorderLayout.SOUTH);
    setPreferredSize(new Dimension(320, 240));
  }

  private static void initMenu(JComponent p) {
    Stream.of(
      new JMenuItem("Open(dummy)"), new JMenuItem("Save(dummy)"),
      new JSeparator(), new JMenuItem(new ExitAction())).forEach(p::add);
  }

  public static void main(String[] args) {
    EventQueue.invokeLater(MainPanel::createAndShowGui);
  }

  private static void createAndShowGui() {
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
      ex.printStackTrace();
      Toolkit.getDefaultToolkit().beep();
    }
    JFrame frame = new JFrame("@title@");
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.getContentPane().add(new MainPanel());
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }
}

class ExitAction extends AbstractAction {
  protected ExitAction() {
    super("Exit");
  }

  @Override public void actionPerformed(ActionEvent e) {
    Component root;
    Container parent = SwingUtilities.getUnwrappedParent((Component) e.getSource());
    if (parent instanceof JPopupMenu) {
      JPopupMenu popup = (JPopupMenu) parent;
      root = SwingUtilities.getRoot(popup.getInvoker());
    } else if (parent instanceof JToolBar) {
      JToolBar toolbar = (JToolBar) parent;
      if (((BasicToolBarUI) toolbar.getUI()).isFloating()) {
        root = SwingUtilities.getWindowAncestor(toolbar).getOwner();
      } else {
        root = SwingUtilities.getRoot(toolbar);
      }
    } else {
      root = SwingUtilities.getRoot(parent);
    }
    if (root instanceof Window) {
      Window window = (Window) root;
      window.dispatchEvent(new WindowEvent(window, WindowEvent.WINDOW_CLOSING));
    }
  }
}

@@ -461,17 +461,21 @@
 MenuBar 
-b
+menuB
 ar = new
@@ -547,17 +547,21 @@
 u);%0A    
-b
+menuB
 ar.add(m
@@ -565,16 +565,86 @@
 d(menu);
+%0A    EventQueue.invokeLater(() -%3E getRootPane().setJMenuBar(menuBar));
 %0A%0A    JT
@@ -872,73 +872,8 @@
 p);%0A
-    add(bar, BorderLayout.NORTH);%0A    add(new JScrollPane(tree));
 %0A   
@@ -907,16 +907,48 @@
 SOUTH);%0A
+    add(new JScrollPane(tree));%0A
     setP
@@ -1055,24 +1055,26 @@
 m.of(%0A      
+  
 new JMenuIte
@@ -1121,16 +1121,18 @@
 mmy)%22),%0A
+  
       ne

use getRootPane().setJMenuBar(mb) instead of add(mb, BorderLayout.NORTH)