简体   繁体   中英

How to remove arrow on JMenuItem?

I need help with JMenuItem. I didn't write any line about arrow on JMenuItem. So how to disable that? Here's the image:

在这里查看图片

Let me try to reproduce the issue.

  • Add JMenuItem in JMenu and then in JMenuBar .

sample code: ( No issues )

JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("A Menu");

JMenu submenu = new JMenu("A submenu");
JMenuItem menuItem = new JMenuItem("Another item");
submenu.add(menuItem);              //comment this line and look the output
menu.add(submenu);

menuBar.add(menu);

在此处输入图片说明


  • Add JMenu directly in JMenuBar without any JMenuItem .

sample code: ( This creates problem )

JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("A Menu");

JMenu submenu = new JMenu("A submenu");
menu.add(submenu);

menuBar.add(menu);

在此处输入图片说明


  • Add JMenuItem directly in JMenuBar .

sample code: ( No issues )

JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("A Menu");

JMenuItem menuItem = new JMenuItem("Another item");
menu.add(menuItem);

menuBar.add(menu);

在此处输入图片说明

Now the problem is crystal clear, if it's leaf node then add JMenuItem instead of JMenu in JMenuBar .

Read more...

I had the same issue with JavaFX with my MenuItems having arrows all over the place.

Thanks to @Braj response I realized that I was creating my items this way:

MenuItem saveMenu = new Menu();

instead of

MenuItem saveMenu = new MenuItem();

This, of course, works in Java thanks to polymorphism but created this side effect in my app. That being said, this can help you better organize your menus using a tree structure like Save > Save to File / Save to DB / Save As...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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