Question

Creating a dynamic proxy (java.lang.reflect.Proxy) causes OS X (at least 10.7 and 10.8) to give focus to the Java application that created the proxy.

The proxy I create wraps an object that starts an external process. This external process expects to have focus and things fail when the Java process steals the focus.

It seems as if OS X is promoting the Java process to the dock and this is the reason it steals the focus from other applications. Does anyone know how to prevent this?

Was it helpful?

Solution

You generally get a dock icon for a Mac Java app if your code touches anything to do with the AWT subsystem. This includes seemingly innocuous things like calculating font metrics, not just the obvious cases like displaying a JFrame.

If your Java code will not need to actually show any GUI components you can set the system property java.awt.headless to the string true to prevent it from starting up the native windowing system (though if you run with this option set and then subsequently do something that does require the native GUI you'll get an exception).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top