I added a JMenuBar to a subclassed JPanel. The menu bar appears in the top center. I'd prefer to have it appear in the top left, but am unable as yet to figure out how to do this. According to the Java Tutorials, JMenuBar uses a BoxLayout? I've tried using the .setAlignment(LEFT_ALIGNMENT) method on the JMenuBar, but this doesn't change the position of the JMenuBar on the JPanel.
Previously, I had placed the JMenuBar in a JFrame, as I only had a single JPanel of content on that frame, and there the constituent JMenus appear in the Top Left corner of the screen, which is what I want to see. But now, I have additional JPanels of content, and each has its own menu needs, which is why I'm trying to play the MenuBars on the JPanels instead of the JFrame.
I have tried adding a "dummy" JMenu to the JMenuBar, but this 2nd simply appears on the right of the first JMenu (as expected) with both in the top center. I tried putting a JMenu of "Box.HORIZONTAL_GLUE" to separate the two JMenus, in hopes of splitting them apart to either corner, but the two JMenus remain contiguous!?
Here is a slightly simplified listing.
Is putting Menu bars on JPanels not a good idea? As I mentioned earlier, my app now uses multiple JPanels of content, and allows navigation between them, and each has its own menu functions. If I put the JMenuBar in the JFrame, I will have to figure out how to alter the contents of the JMenuBar depending upon which JPanel is current. I thought I'd check in as see if there was something I missed (concerning the positioning of JMenuBars on JPanels) before resorting to that.
Ah, also: the subclassed JPanel was left with its default layout. That would be a Flow layout, flowing from left to right, yes? Is a JMenuBar even subject to this layout, since it is something that usually hangs from the top of the container, not an item being presented at any point within the container? The other objects on my JPanels are all using absolute positioning.