2

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?

Lyndon
  • 573
  • 6
  • 24
  • Have you taken a look at any open-source Java-made application popular among Mac users (I don't know any as I am not a Mac user)? – Ivan Mar 13 '12 at 18:15

2 Answers2

2

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?

cello
  • 5,356
  • 3
  • 23
  • 28
  • cello, you are indeed correct. The Search box has appeared. Well done and thanks. – Lyndon Mar 13 '12 at 23:07
  • What about other languages? For instance, "Help" translates into: "Aide" in French, "Aiuto" in Italian, "Ayuda" in Spanish, "Ajuda" in Portuguese, "Hilfe" in German, "Hulp" in Dutch, "Hjälp" in Swedish. Please see my [post](https://stackoverflow.com/questions/42620642/macos-search-feature-in-internationalized-help-menu) to see screenshots of the problem. – Géry Ogam Mar 06 '17 at 21:52
0

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 |
|+-------------------------+       |
+----------------------------------+
JTeagle
  • 2,196
  • 14
  • 15