javaswingjmenujmenubarjseparator

Component inside JMenuBar wants to align far right after JSeparator?


Take a look at this image:

enter image description here

As you can see, I have a JSeparator between my "Auto Refreshing" JCheckBox and my "Show Column" menu, and my "Show Column" menu is wanting to be as far right as possible. Why is it not aligning itself to the left, like everything else before the JSeparator? And I can't seem to make it do so, here is my current code:

JCheckBox pulling = new JCheckBox("Auto Refreshing");
...
menuBar.add(pulling);

menuBar.add(new javax.swing.JSeparator(javax.swing.SwingConstants.VERTICAL));

JMenu showMenu = new JMenu("Show Column");
showMenu.setAlignmentX(Component.LEFT_ALIGNMENT);
menuBar.add(showMenu);

Solution

  • The issue was the size of the JSeparator, it wanted to take up as much horizontal space as possible. So, my solution was to restrict it's size so that it could only be one pixel wide max:

    JSeparator menuSep = new JSeparator(javax.swing.SwingConstants.VERTICAL);
    menuSep.setMaximumSize(new java.awt.Dimension(1, 1000));
    menuBar.add(menuSep);