Jonatan
Jonatan

Reputation: 297

Creating a dynamic proxy in Java steals focus on OS X

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?

Upvotes: 2

Views: 175

Answers (1)

Ian Roberts
Ian Roberts

Reputation: 122424

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).

Upvotes: 3

Related Questions