I am adding a second approach. You could use setBorder
method:
menuBar.setBorder(BorderFactory.createLineBorder(Color.BLUE, 2));
This solution has the advantage that you can set the level of thickness. In the example above level of thickness is set to 2.
Also you can use setBorder in many components to paint various borders as in the example below:
First the basic code:
Main class:
import javax.swing.*;
public class Main {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
CustomGUI sw = new CustomGUI();
sw.setVisible(true);
});
}
}
CustomGui.class:
import java.awt.*;
import javax.swing.*;
public class CustomGUI extends JFrame {
public CustomGUI() {
super("Simple example");
setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
setSize(500,500);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().setBackground(Color.DARK_GRAY);
JMenuBar menuBar = new JMenuBar();
JMenu menu1 = new JMenu("menu B");
menuBar.add(menu1);
JMenuItem item = new JMenuItem("A text-only menu item");
menu1.add(item);
JMenu menu2 = new JMenu("menu B");
menuBar.add(menu2);
JMenuItem item2 = new JMenuItem("A text-only menu item");
menu2.add(item2);
add(menuBar);
}
}
Now by adding line:
menuBar.setBorder(BorderFactory.createLineBorder(Color.BLUE, 2));
in CustomGUI()
we get:

Now if we want to add border to jmenu's (which is what the OP asked) as well add:
menu1.getPopupMenu().setBorder(BorderFactory.createLineBorder(Color.BLUE, 4));
menu2.getPopupMenu().setBorder(BorderFactory.createLineBorder(Color.BLUE, 4));
(as you can see in the image i didn't set border for menubar but this could be done as described above using:
menuBar.setBorder(BorderFactory.createLineBorder(Color.BLUE, 2));
And also I added another item just for the menu to be bigger and easier to see the border...)