I like to develop in Java but also want compatibility with the global menu? Is there a way? Please help.


There is a library called java-gnome (a java gtk wrapper) that allows your apps to behave like all of the native apps. It provides all the glory to them: native widgets, global menu, etc.

The library is available on the ubuntu repositories:

The goal of the library is to develop a rich Java + Gnome experience. Beware, that if you use this library your app will lose the multiplatform feature of Java (since it'll be tied to java-gnome).

Here is a sample app (that comes with java-gnome) displaying the menu integration:

Example App

  • Have you confirmed that libjava-gnome supports libdbusmenu at all? Unity is not Gnome, after all. Also, I think switching to another GUI toolkit just in order to use a dbus service to be fairly radical. – Jo-Erlend Schinstad Jan 29 '12 at 15:36
  • Yes, I've confirmed :). – Marcos Roriz Junior Feb 3 '12 at 3:47

Try Ayatana. You may find instructions here: http://hanynowsky.wordpress.com/2012/05/12/integration-of-java-swing-applications-with-unity-global-menu-in-ubuntu-12-04/

All you have to do is to import the Java Ayatana Library and call it in your main JFrame class. This actually implies the addition of the following couple of lines in your code (as well as importing Ayatana classes):

if (AyatanaDesktop.isSupported())

Here is an example:

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import org.java.ayatana.ApplicationMenu;
import org.java.ayatana.AyatanaDesktop;
public class MyAppWithUnityMenu {
public MyAppWithUnityMenu () {
    JFrame mainFrame = new JFrame("This app integrates in Unity menu bar");
// set up mainFrame, by adding components, etc.
    JPanel panel = new JPanel();
    panel.add(new JLabel("This is a sample application for testing menu integration in Unity. Enjoy!"));
    mainFrame.addWindowListener ( new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
 // set up the menu bar, by adding menus, etc.
  JMenuBar menuBar = new JMenuBar();
  JMenu file = new JMenu("File");
  file.add(new JMenuItem("Open"));
  file.add(new JMenuItem("Save"));
  file.add(new JMenuItem("Close"));
  JMenu edit = new JMenu("Edit");
  edit.add(new JMenuItem("Copy"));
  edit.add(new JMenuItem("Cut"));
  edit.add(new JMenuItem("Paste"));
  JMenu help = new JMenu("Help");
  help.add(new JMenuItem("Help topics"));
  help.add(new JMenuItem("About"));
   // Java Ayatana Call
  if (AyatanaDesktop.isSupported()) { 
public static void main(String[] args) {
    new MyAppWithUnityMenu();

And the most important thing is that your application is still cross-platform. I have tested the above example in both Ubuntu 12.04 LTS and Windows XP.


You can use a ppa: ppa:danjaredg/jayatana



That is normally done at the toolkit level, for instance in GTK or Qt. So the intended way to do it would be to patch Swing, if that's the GUI toolkit you're using. However, all the Unity components communicate using DBus, so if you really wanted to, you could do it yourself by implementing the DBus API yourself. If you want to do this, you might want to have a look at libdbusmenu and see how it works.

  • -1 for not a real answer and for asking the op to implement the dbus stuff. – Marcos Roriz Junior Jan 29 '12 at 14:25
  • 1
    Not a real answer? How can you say that? I answered precisely what was asked. The OP did not ask how to port a Swing application to GTK. – Jo-Erlend Schinstad Jan 29 '12 at 15:34

Not a fix for you, but FYI: I filed Ubuntu bug #984916 to track the fact that Swing menus are not (semi-)automatically integrated into the global menu.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.