Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Making an application "active" from java



OK, I've switched to Quentin's method, and it seems to work fine.  I
don't mind setting the CLASSPATH, as I'm already using it in a real
Mac app.  Here's the code I'm using, in case anyone else wants to try
it.

Bill

try {
    
    Class applicationClass = Class.forName("com.apple.cocoa.application.NSApplication");
    if (applicationClass != null) {
	// make this application active
	java.lang.reflect.Method getShared = applicationClass.getDeclaredMethod("sharedApplication", null);
	if (getShared != null) {
	    Object sharedApp = getShared.invoke(null, null);
	    Class[] argTypes = { boolean.class };
	    java.lang.reflect.Method makeActive = applicationClass.getDeclaredMethod("activateIgnoringOtherApps", argTypes);
	    if (sharedApp != null && makeActive != null) {
		Object[] args = new Object[] { new Boolean(true) };
		makeActive.invoke(sharedApp, args);
	    }
	}
    }

} catch (NoClassDefFoundError e) {
    // not on a Mac, or bad classpath
} catch (ClassNotFoundException e) {
    // not on a Mac, or bad classpath
} catch (Exception e) {
    System.err.println("Exception while attempting to make application active!");
    e.printStackTrace(System.err);
}
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden

References: 
 >Re: Making an application "active" from java (From: Quentin Stafford-Fraser <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.