简体   繁体   English

Java JMenuItem在第二个menuItem之后添加边框

[英]Java JMenuItem add a border after the second menuItem

I was trying to add some menu and wondering how can I add a border after the second menuItem 我试图添加一些菜单,想知道如何在第二个菜单项之后添加边框

Just like this 像这样

Image Here 图片在这里

here is my code 这是我的代码

jmb = new JMenuBar();
jmb.setPreferredSize(new Dimension(43,30));

jmMenu = new JMenu("Menu");
jmSettings = new JMenu("Settings");

jmiMenu = new JMenuItem("Add User"); 
jmiMenu.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e)
    {
        System.out.print("Rod click menuItem");
    }
});
jmiMenu.setPreferredSize(new Dimension(200,25));
jmiExit = new JMenuItem("Exit");
jmiExit.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e)
    {
        System.out.print("Rod click exit");
    }
});

jmb.add(jmMenu);
jmb.add(jmSettings);

jmMenu.add(jmiMenu);
jmMenu.add(jmiExit);

add(jmb);

That is not a border, that is called a "separator" within the menus. 那不是边框,在菜单中称为“分隔符”。 Add this after the 2nd menuitem 在第二个菜单项之后添加

    jmMenu.addSeparator();

That will put the line across the menus, and will give you the output as in the image. 这将使菜单中的一行显示在菜单中,并为您提供图像中的输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM