Adding a JMenuBar to the two components of a JSplitPane

Main.java:

import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
 
public class Main extends JFrame
{
   JSplitPane splitPane;
  
   public Main() {
      addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent we) {
            System.exit(0);
         }
      });
 
      JPanel firstPanel = createPanel();
      JPanel secondPanel = createPanel();
      splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, firstPanel, secondPanel);
 
      createMainMenuBar();
 
      getContentPane().add(splitPane);
      setSize(300, 300);
      setVisible(true);
 
      splitPane.setDividerLocation(0.5); 
   }
 
   public void createMainMenuBar() {
      JMenuBar mainBar = new JMenuBar();
      JMenu menu = new JMenu("JSplitPane");
      JMenuItem item1 = new JMenuItem("HORIZONTAL_SPLIT");
      JMenuItem item2 = new JMenuItem("VERTICAL_SPLIT");
      menu.add(item1);
      menu.add(item2);
      mainBar.add(menu);
      setJMenuBar(mainBar);
 
      item1.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent ae) {
            splitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
         }
      });
 
      item2.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent ae) {
            splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
         }
      });
   }
 
   public JPanel createPanel() {
      JPanel panel = new JPanel();
      panel.setLayout(new BorderLayout());
      JMenuBar menuBar = new JMenuBar();
      for (int i=0; i<3; i++) {
         JMenu menu = new JMenu("JMenu " + (i+1));
         for (int j=0; j<3; j++) {
            JMenuItem item = new JMenuItem("JMenuItem " + (j+1));
            menu.add(item);
         }
         menuBar.add(menu);
      }
      panel.add(BorderLayout.NORTH, menuBar);
 
      return panel;
   }
 
   public static void main(String []args) {
      Main main = new Main();
   }
}