hello ewjordan,
after a leopard update everything was working ... very strange, don't know what the mistake was.
actually i don't understand 100% what is going on in this piece of code, i was able to extended it with shortcuts. you can trigger now the menu in the usual way. nice.
the code runs fine on leopard and vista.
one last thing, does anybody know how to edit the standard menu about item ("About processing.core.PApplet Version 12.0.0 (12.0.0)"?
Code:
//how to create a menubar with hotkeys
Menu fm;
MenuItem ol,sl;
int i;
void setup(){
size(400,400);
this.frame.setTitle("example: a menubar with hotkeys");
MenuBar mb = new MenuBar();
mb.add(fm = new Menu("File"));
fm.add(ol = new RedirectingMenuItem(this,"Open", new MenuShortcut( KeyEvent.VK_O )));
fm.add(sl = new RedirectingMenuItem(this,"Save", new MenuShortcut( KeyEvent.VK_S )));
this.frame.setMenuBar(mb);
background(0);
}
void draw(){
background(i%=255);
i++;
}
boolean action(Event e, Object arg) {
if (e.target == ol) {
println("Here's where you would put your file loading code.");
return true;
}
else if (e.target == sl) {
println("And here's where you would save.");
}
return super.action(e,arg);
}
public class RedirectingMenuItem extends MenuItem {
private Component event_handler;
public RedirectingMenuItem(Component event_handler, String label, MenuShortcut hotkey) {
super(label,hotkey);
this.event_handler = event_handler;
}
public boolean postEvent(Event e) {
if (event_handler.isValid()) return event_handler.postEvent(e);
else return false;
}
}