Aphex
Aphex

Reputation: 408

Group JMenuItems in Java

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: From Google Chrome on Mac 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

Answers (1)

Hovercraft Full Of Eels
Hovercraft Full Of Eels

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

Related Questions