Adding spacing between elements in JMenuBar

Andrei0427 picture Andrei0427 · Aug 31, 2012 · Viewed 9.1k times · Source

Elements such as File, Edit etc. are too close together when using the JMenuBar in my application, it would look much nicer if there were some space between the elements. Is this possible?

Answer

mKorbel picture mKorbel · Aug 31, 2012

required to add JComponents that aren't focusable, you can create an space for

  1. JMenuBar

    • JLabel (have to set for required PreferredSize)

    • JSeparator (minimus size is 10pixels, have to setOpaque for JSeparator)

  2. JMenuItem

    • JSeparator (no additional settings required)

    • JLabel (have to set for required PreferredSize)