You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Jeremy <mo...@gmail.com> on 2012/02/17 01:24:15 UTC
Desktop application top level menu hack - is there a better way?
Goal: to have top level menu as per native application (e.g. Mac OSX menu or Windows main window menu).
I could not find a way (using pivot components) in tutorials, mail list, google.
Is there a better way to do this than by directly using Java AWT Frame and menus?
e.g.
public static void main(String[] args) {
System.setProperty("apple.laf.useScreenMenuBar", "true");
DesktopApplicationContext.main(MyMainClass.class, args);
java.awt.Frame[] activeframes = java.awt.Frame.getFrames();
for (java.awt.Frame f : activeframes) {
if (f.isVisible()) {
f.setMenuBar(createMenuBar());
}
}
}
public static java.awt.MenuBar createMenuBar() {
java.awt.MenuBar menuBar = new java.awt.MenuBar();
menuBar.add(createFileMenu());
return menuBar;
}
public static java.awt.Menu createFileMenu() {
java.awt.Menu m = new java.awt.Menu("File");
MenuItem mi = new MenuItem( "Open", new MenuShortcut( KeyEvent.VK_O ));
mi.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
System.out.println("****** OPEN ******");
}
});
m.add(mi);
return m;
}
Re: Desktop application top level menu hack - is there a better way?
Posted by Sandro Martini <sa...@gmail.com>.
Hi all,
if you need a standard Menu Bar, you can look at the following Tutorial,
live from here:
http://pivot.apache.org/tutorials/menu-bars.html
and there is a sample of it even inside our "Kitchen Sink" Demo, under the
Menus link.
But if you need a Top Menu outside the application (or better, a Menu for
the desktop, in OS X Style) we don't have something like this, sorry.
But you could file a JIRA for this (could be good for a future release, but
in this case the problem would be how to implement it in a multi-platform
way), and if you have some code/concept/prototype, attach there and tell to
us.
Otherwise you can try to put an Application in Full Screen mode, and use a
standard Menu Bar ... but you have to try and see what happens.
Bye,
Sandro
RE: Desktop application top level menu hack - is there a better way?
Posted by Camilo Casadiego <Ca...@adv.co>.
you mean like this??
[cid:image001.png@01CCED6B.D91C0EC0]
Cordialmente,
[cid:image002.png@01CCED6B.D91C0EC0]
Camilo Casadiego Espitia
Arquitecto de SW
* + 57 1 6393000
* camilo.casadiego@adv.com.co<ma...@adv.com.co>
* http://www.adv.com.co<http://www.adv.com.co/>
Carrera 11 No. 93 - 53 P7
Bogotá - Colombia
De: Jeremy [mailto:moore.jere@gmail.com]
Enviado el: Thursday, February 16, 2012 7:24 PM
Para: user@pivot.apache.org
Asunto: Desktop application top level menu hack - is there a better way?
Goal: to have top level menu as per native application (e.g. Mac OSX menu or Windows main window menu).
I could not find a way (using pivot components) in tutorials, mail list, google.
Is there a better way to do this than by directly using Java AWT Frame and menus?
e.g.
public static void main(String[] args) {
System.setProperty("apple.laf.useScreenMenuBar", "true");
DesktopApplicationContext.main(MyMainClass.class, args);
java.awt.Frame[] activeframes = java.awt.Frame.getFrames();
for (java.awt.Frame f : activeframes) {
if (f.isVisible()) {
f.setMenuBar(createMenuBar());
}
}
}
public static java.awt.MenuBar createMenuBar() {
java.awt.MenuBar menuBar = new java.awt.MenuBar();
menuBar.add(createFileMenu());
return menuBar;
}
public static java.awt.Menu createFileMenu() {
java.awt.Menu m = new java.awt.Menu("File");
MenuItem mi = new MenuItem( "Open", new MenuShortcut( KeyEvent.VK_O ));
mi.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
System.out.println("****** OPEN ******");
}
});
m.add(mi);
return m;
}