There are two standard ways to add custom spacing to Swing components.
One standard way is to use setMargin for JMenu objects contained in a JMenuBar object. This is the method suggested by Gabriel Camara above for JMenuItem. It is also supposed to work with JMenu objects, but I tried, and it didn't work.
The second standard way to do this is to add an EmptyBorder to JMenu objects. This works perfectly fine and gives you full control over the exact distances you want in all directions.
JMenu jMenuFile = new JMenu("File") jMenuFile.setBorder(new EmptyBorder(0, 10, 0, 10));
source share