We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › create menus in processing
Page Index Toggle Pages: 1
create menus in processing? (Read 910 times)
create menus in processing?
May 4th, 2008, 5:30pm
 
hello all,

i'd like to create menus like "open file" or "export file" for my application ... i already found under hacks the filechooser hack, which works fine for me:
http://processing.org/hacks/doku.php?id=hacks:filechooser

but still i'm not able to create a menubar item, there is an old post about this topic:  
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Syntax;action=display;num=1184371214;start=0#0

but unfortunately this code seems not too work with my setup (processing 0135, macos 10.5.2). so any idea how to do it?

thanks
benedikt
Re: create menus in processing?
Reply #1 - May 4th, 2008, 6:06pm
 
hi, I had the same problem some time ago, and I ended up using the controlP5 library and its MultiList class. it could fit your needs too, maybe.
Re: create menus in processing?
Reply #2 - May 4th, 2008, 7:35pm
 
thanks for the hint antiplastik!

but this is not exactly what i am looking for ... i would prefer the "standard menu" way.
Re: create menus in processing?
Reply #3 - May 5th, 2008, 2:27am
 
Hmm, what problem are you having with that AWT menu code?  I just checked in Vista (not booted into OS X at the moment, and haven't tried it since I upgraded to Leopard), and a simple cut and paste of that code seems to work fine with 0135.  Are you actually getting an error, or is nothing showing up in the menu bar?  Also, what JVM version are you running?
Re: create menus in processing?
Reply #4 - May 5th, 2008, 1:47pm
 
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;
}
}
Re: create menus in processing?
Reply #5 - May 8th, 2008, 4:41am
 
Hmm, interestingly enough the about menu doesn't appear to be accessible, at least as far as I could tell with a little searching, through AWT.  It looks like you can do a few things using the com.apple.eawt package on OS X, but I'm not sure about how to do it in a cross-platform way.  Even just to change the name that appears seems like it either takes extra files to be added to the project or some change to the arguments passed when it is run...

FWIW, I think that 12.0.0 is actually the OS X Java plugin version string, not anything actually having to do with Processing, though I could be wrong about this.  I don't remember the situation on Windows.  I couldn't find much concrete info on this anywhere - seems like the best way to do well integrated Java apps these days is to use Swing and develop within Eclipse/Netbeans or some other full Java IDE.
Page Index Toggle Pages: 1