JDK-8118714 : Mac: Headless environment issue, MacOSX
  • Type: Bug
  • Component: javafx
  • Sub-Component: swing
  • Affected Version: fx2.1
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2012-04-03
  • Updated: 2015-06-17
  • Resolved: 2013-03-01
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8Fixed
Related Reports
Blocks :  
Blocks :  
Duplicate :  
Relates :  
Relates :  
Description
Graphics environment is still forced to be headless under Mac.

Sample (just to illustrate problem):

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;


import com.sun.javafx.application.PlatformImpl;
import javafx.scene.Scene;
import javafx.embed.swing.JFXPanel;

import javafx.scene.control.Button;
import javafx.scene.layout.VBox;

public class Main {

    private JFXPanel javafxPanel;
    private Scene scene;

    public Main() {
        JFrame frame = new JFrame("Swing interop");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        javafxPanel = new JFXPanel();
        javafxPanel.setPreferredSize(new Dimension(550, 400));
        frame.getContentPane().add(javafxPanel, BorderLayout.CENTER);
        createScene();

        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }

    private void createScene() {
        PlatformImpl.startup(new Runnable() {

            public void run() {
                VBox root = new VBox();
                scene = new Scene(root);
                root.getChildren().add(new Button("FXButton"));
                javafxPanel.setScene(scene);
            }
        });
    }


    public static void main(String[] args) {
        Button btn = new Button("");
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new Main();
            }
        });
    }
}

Comments
This indeed requires fixes in JDK. We don't have plans to back port these specific changes to 7uX releases because they are somewhat risky, and we don't want to destabilize the 7uX branch. As Steve suggests, please move to 8. AFAIK, apart from the fact that FX forces the AWT to run in the headless mode, nothing else changes or breaks because of this. So you may assume that the warning printed out to the console is the only side-effect of the missing changes. As long as you don't need to use AWT/Swing in your application, you should be safe.
17-12-2013

Thanks, I understand your point about JVM changes. For development I have no trouble waiting for Java 8 GA, but are you sure that this does not impact production environments, particularly end-users who may not wish to upgrade? I have no anwers, I just thought it worth raising the question.
17-12-2013

Anthony? My understanding was that there are also JVM changes as well as FX changes. Note that by the time the next 7 update release is out, jdk8 will have shipped. It would be best to move to 8.
17-12-2013

User here, I'm not sure if this is appropriate, but I was directed to JIRA from a forum thread. This appeared in my console log whist launching a JavaFX app that uses no uses no Swing components, and I was wondering if the fix could be back-ported to Java 7 (my understanding is that "Lombard" above is the code name for JDK 8). 17-12-2013 15:04:52.554 java[649]: [JRSAppKitAWT markAppIsDaemon]: Process manager already initialized: can't fully enable headless mode. I can launch the jar from the command-line, and of course I could bundle it, but bugs like this bother me, and I think Java 7 should be patched also.
17-12-2013

verified with b104
28-08-2013

ControlsAutomatedTestSuite/javafx/scene/control/test/jfxpanel/JFXPanelBrowserTest/browserTest
30-04-2013

Target build: b80
19-04-2013

Affected tests: javafx/scene/control/test/manual/ChooserManual.java
15-04-2013

This is a crash in JDK. Please file a bug report against AWT at http://bugs.sun.com/ and attach a short test case to your report so that we could reproduce it. Also, what JDK/FX versions are you using? I suggest to try the latest 8-ea build (available at http://jdk8.java.net/download.html) and see if the issue is still reproducible.
07-02-2013

I have now tried java.awt.Toolkit.getDefaultToolkit() instead. What happens then is essentialy this: RT-15698 (i.e. the Cocoa blocked in runLoop), and I followed your latest comment on that issue: """ Even though your app doesn't use the JFXPanel, it is still run in a VM where AWT has already been initialized. As such this use case is embedded by its nature, and FX/Glass should be initialized with the -Djavafx.macosx.embedded=true system property set whatsoever. On the other hand, I'm not quite sure if FX currently supports launching in the embedded mode via the Application.launch() code path. I agree that this scenario might be useful in some cases, however, I'm not sure we ever planned to have support for it. """ When starting with Djavafx.macosx.embedded=true, my application starts fine, but when a library that we use spawns a Swing window, this happens: 2013-02-07 15:16:36.135 java[16226:2517] Cocoa AWT: Running on AppKit thread 0 when not expected. ( 0 liblwawt.dylib 0x0000000164831d24 Java_com_apple_eawt_Application_nativeInitializeApplicationDelegate + 40 1 ??? 0x000000010ae57f90 0x0 + 4477779856 2 ??? 0x000000010ae4c158 0x0 + 4477731160 3 ??? 0x000000010ae464f7 0x0 + 4477707511 4 libjvm.dylib 0x000000010a45152f _ZN9JavaCalls11call_helperEP9JavaValueP12methodHandleP17JavaCallArgumentsP6Thread + 557 5 libjvm.dylib 0x000000010a4512fc _ZN9JavaCalls4callEP9JavaValue12methodHandleP17JavaCallArgumentsP6Thread + 40 6 libjvm.dylib 0x000000010a425e91 _ZN13instanceKlass27call_class_initializer_implE19instanceKlassHandleP6Thread + 145 7 libjvm.dylib 0x000000010a42734f _ZN13instanceKlass15initialize_implE19instanceKlassHandleP6Thread + 1469 8 libjvm.dylib 0x000000010a4197e3 _ZN13instanceKlass10initializeEP6Thread + 83 9 libjvm.dylib 0x000000010a4fcd15 _ZN12LinkResolver19resolve_static_callER8CallInfoR11KlassHandleP6SymbolS5_S2_bbP6Thread + 169 10 libjvm.dylib 0x000000010a4fcdfb _ZN12LinkResolver20resolve_invokestaticER8CallInfo18constantPoolHandleiP6Thread + 129 11 libjvm.dylib 0x000000010a44ce77 _ZN18InterpreterRuntime14resolve_invokeEP10JavaThreadN9Bytecodes4CodeE + 507 12 ??? 0x000000010ae6307a 0x0 + 4477825146 13 ??? 0x000000010ae4c333 0x0 + 4477731635 ) 2013-02-07 15:16:36.136 java[16226:2517] Please file a bug report at http://java.net/jira/browse/MACOSX_PORT with this message and a reproducible test case.
07-02-2013

Henrik: "new Frame()" is not enough because this won't initialize the native AWT toolkit. I suggest to call: java.awt.Toolkit.getDefaultToolkit(); instead. This way you avoid creating a dummy frame, and get the toolkit fully initialized.
07-02-2013

Anthony: I tried workaround this issue using the method you mentioned (initialize AWT before calling the launch method). Here's what I do: new Frame(); // This is my interpretation of initializing AWT Application.launch( MyApplication.class, args ); This works on Windows but not on Mac. On Mac, the program gets stuck at Application.launch() -- MyApplication.start() is never called. Am I initializing AWT in the wrong way?
07-02-2013

A fix for 8005465 is now in both JDK 8 and jdk7u-dev (to become 7u14) repositories. The rest of the fix is in Quantum. Assigning this issue to Thor.
18-01-2013

I have pushed a partial fix that enables Glass to determine if it's running embedded automatically. I.e. it's no longer required to set the javafx.macosx.embedded system property for this purpose. At this moment, if you initialize AWT/Swing (or SWT for that matter) first, and then call FX's launch() method, everything should just work. The scenario when the AWT is initialized after FX has started is still unsupported. The next steps to finally resolve the issue are: 1. Fix Gtk port of Glass: RT-27218 2. Fix JDK so that it doesn't require the -XstartOnFirstThread option for AWT to start up successfully in embedded mode. See JDK bug 8005465 for details. 3. Finally remove setting the java.awt.headless property from Quantum. Once all the above changes are applied, there will no longer be a requirement to start AWT and FX in a particular order. Any order will do, and both toolkits will be able to run headful.
26-12-2012

JFXPanel clearly shows that FX (Glass/Prism) and JDK (AWT/Java2D) can co-exist on OS X. The problem is initialization: what is initialized first, whether application should explicitly request interoperability mode (system property), or FX/JDK can detect is automatically. My proposal for how the fix can look like: 1. Make "initialize AWT first, then FX" the only supported initialization order, so applications that use both FX and JDK should explicitly initialize AWT first. 2. Glass should detect if anyone else (AWT, SWT) has already called [NSApp run]. If this is the case, Glass shouldn't run its own event loop. 3. Remove "javafx.macosx.embedded" system property from JFXPanel.initFx(). 4. Remove "java.awt.headless" workaround from QuantumToolkit.init(). The next step will be to file a new bug against AWT, so it is as friently to other UI toolkits running in the same process as Glass. AWT can already handle the case, when it's embedded into SWT. It should be extended to support embedding into FX as well.
24-12-2012

Artem: can you take a look at this?
21-12-2012

Hi, I get the same issue without JFXPanel, only by mixing JavaFX stage and a Swing JFrame creation. On my Mac, only the stage is displayed the Swing part generates the following stack trace. I also tried with the VM argument -Djava.awt.headless=false without any success. All is fine under Windows... Thanks 2012-12-19 16:22:29.338 java[1189:2207] [JRSAppKitAWT markAppIsDaemon]: Process manager already initialized: can't fully enable headless mode. Exception in thread "AWT-EventQueue-0" java.awt.HeadlessException at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:207) at java.awt.Window.<init>(Window.java:535) at java.awt.Frame.<init>(Frame.java:420) at java.awt.Frame.<init>(Frame.java:385) at javax.swing.JFrame.<init>(JFrame.java:180) at experiment.fx.JavaFXApplicationAndSwing$1.run(JavaFXApplicationAndSwing.jav a:23) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:721) at java.awt.EventQueue.access$200(EventQueue.java:103) at java.awt.EventQueue$3.run(EventQueue.java:682) at java.awt.EventQueue$3.run(EventQueue.java:680) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.j ava:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:691) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.jav a:244) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:1 63) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.jav a:151) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139) at java.awt.EventDispatchThread.run(EventDispatchThread.java:97) Code: import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.StackPane; import javafx.stage.Stage; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.SwingUtilities; public class JavaFXApplicationAndSwing extends Application { @Override public void start(Stage primaryStage) { // Swing Part SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JFrame jFrame = new JFrame(); jFrame.setBounds(10, 10, 320, 240); jFrame.getContentPane().add(new JButton("I am a Swing Button!")); jFrame.setVisible(true); } }); // Back to JFX Button btn = new Button(); btn.setText("Say 'Hello World'"); btn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { System.out.println("Hello World!"); } }); StackPane root = new StackPane(); root.getChildren().add(btn); Scene scene = new Scene(root, 300, 250); primaryStage.setTitle("Hello World!"); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } }
20-12-2012

So what is the impact of running in headless mode to creating a new JFXPanel?
27-11-2012

Affected tests: ControlsAutomatedTestSuite/javafx/scene/control/test/jfxpanel/JFXPanelScrollTest/resizingTest ControlsAutomatedTestSuite/javafx/scene/control/test/jfxpanel/JFXPanelTest/initialSizesTest ControlsAutomatedTestSuite/javafx/scene/control/test/jfxpanel/JFXPanelTest/mainSceneTest ControlsAutomatedTestSuite/javafx/scene/control/test/jfxpanel/JFXPanelTest/transparencyTest
25-09-2012

Note that we currently get the following warning on Mac if we try to initialize AWT (e.g., by using the J2D pipeline or by loading some other library that uses AWT): java[...] [JRSAppKitAWT markAppIsDaemon]: Process manager already initialized: can't fully enable headless mode.
04-09-2012

SQE / OK
20-07-2012

This is too risky to even consider for 2.2 (and may not even be possible without JDK support). This one was not ever intended to be fixed in 2.2 (we moved it to Lombard a long time ago).
20-07-2012

We may need support from the JDK to enable us to solve it. However, we do need to solve the issue in order to address RT-17383 (printing) and fix RT-13739 among other problems. As a quick test, we should comment out the enabling of headless mode and see whether this causes any problems when running JavaFX 2.2 on JDK7u4 for Mac.
03-04-2012