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.
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);
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);
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
.
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.