Reputation: 408
I am creating an application in Java in which I would like the Menu Items to be grouped like we see in many applications.
Here is an example: Notice how a gray bar is visually separating the options. How is this done in Java (Swing) — can it be done?
Upvotes: 2
Views: 261
Reputation: 285405
The JMenu API describes an addSeparator()
method that should do just what you want.
i.e.,
JMenu editMenu = new JMenu("Edit");
editMenu.add(new JMenuItem("Foo"));
editMenu.add(new JMenuItem("Bar"));
editMenu.addSeparator();
editMenu.add(new JMenuItem("Baz"));
editMenu.add(new JMenuItem("Bif"));
Upvotes: 3