Lyndon
Lyndon

Reputation: 613

How to Implement the Help menu in a Java Swing App

OSX apps have a Help menu on the right of the menu bar. When the Help menu is click, a menu opens with a search box at the top and a few menu items under it.

How can this be achieved in a Java Swing app?

Upvotes: 2

Views: 1831

Answers (2)

cello
cello

Reputation: 5486

Just add a JMenu with the name set to "Help" and add it to the JMenuBar. At least in my application running on an english OS X (Snow Leopard and Lion, Java 6), the search field is automatically added to the Help menu by the system. Did you already try this? If it did not work, what Java version and OS version do you use?

Upvotes: 2

JTeagle
JTeagle

Reputation: 2196

If you're going to write Java code then trying to make the UI look like anyone particular OS is not such a good idea - it isn't going to look right to other users.

By default menu items are buttons. You might be able to derive a class from JMenuItem that adds a text box into its client area, while retaining button click functionlity for the 'Search' icon. I have no idea whether this will actually work, so consider this a disclaimer.

+--- Bounds of normal JMenuItem ---+
|+-------------------------+ Search|
||          JTextField     |  icon |
|+-------------------------+       |
+----------------------------------+

Upvotes: 0

Related Questions