Java JMenuBar.setMargin(Insets m)

Syntax

JMenuBar.setMargin(Insets m) has the following syntax.

public void setMargin(Insets m)

Example

In the following code shows how to use JMenuBar.setMargin(Insets m) method.


import java.awt.Insets;
import java.awt.event.KeyEvent;
// w  w w.  j  a v  a 2 s  . c  o  m
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JRadioButtonMenuItem;

public class Main {
  public static void main(String args[]) {
    JFrame f = new JFrame("JRadioButtonMenuItem Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JMenuBar bar = new JMenuBar();
    bar.addNotify();
    JMenu menu = new JMenu("Options");
    menu.setMnemonic(KeyEvent.VK_O);

    ButtonGroup group = new ButtonGroup();

    JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem("A");
    group.add(menuItem);
    menu.add(menuItem);

    menuItem = new JRadioButtonMenuItem("B");
    group.add(menuItem);
    menu.add(menuItem);

    menuItem = new JRadioButtonMenuItem("C");
    group.add(menuItem);
    menu.add(menuItem);

    bar.add(menu);
    
    bar.setMargin(new Insets(3,3,3,3));
    
    f.setJMenuBar(bar);
    f.setSize(300, 200);
    f.setVisible(true);
  }
}