javaswingjframejmenujtoolbar

JToolBar/JMenu position overlap


I am trying to put on a JMenu and JToolbar in the NORTH position of a JFrame but they overlap each other. Is there any way to put both on NORTH position?


Solution

  • Don't attempt to add both components to the NORTH of the frame.

    The frame reserves a special location for the menu bar. So your code should be somethink like:

    frame.setJMenuBar( menuBar );
    frame.add(northPanel, BorderLayout.PAGE_START);
    

    Read the section from the Swing tutorial on How to Use Menu for more information and working examples to get you started.