import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
public class JFrameExample2 {
JFrame f = new JFrame();
JMenuBar mbar = new JMenuBar();
JMenu menu1 = new JMenu("Menu1");
JMenu menu2 = new JMenu("Menu2");
JMenu menu3 = new JMenu("Menu3");
JMenuItem mitem1 = new JMenuItem("1");
JMenuItem mitem2 = new JMenuItem("2");
JMenuItem mitem3 = new JMenuItem("3");
public JFrameExample2() {
menu1.add(mitem1);
menu2.add(mitem2);
menu3.add(mitem3);
mbar.setLayout(new GridBagLayout());
GridBagConstraints gc = new GridBagConstraints();
gc.fill = GridBagConstraints.HORIZONTAL;
gc.gridwidth = 1;
gc.weightx = 0;
gc.gridx = 0;
mbar.add(menu1, gc);
gc.weightx = 1;
gc.gridx = 1;
mbar.add(new JLabel(),gc);
gc.weightx = 0;
gc.gridx = 2;
mbar.add(menu2, gc);
gc.weightx = 1;
gc.gridx = 3;
mbar.add(new JLabel(),gc);
gc.weightx = 0;
gc.gridx = 4;
mbar.add(menu3, gc);
f.setJMenuBar(mbar);
f.setSize(400,400);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
public static void main(String[] args) {
JFrameExample2 test = new JFrameExample2();
}
}