Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No window comes up when running javafx application

Running JavaFX application using VM argument. Program compiles and runs. Using Eclipse on MacOS. When the program runs it shows the java coffee cup logo in the dock, but no window comes up.

I want to be able to run this program successfully. I believe it's an Eclipse configuration issue rather than code.

I had a lot of issues getting JavaFX to run on Eclipse for Mac with the main one being that libraries did not exist and would not import. I was able to get it to work by downloading JavaFX from here (https://gluonhq.com/products/javafx/), creating a user defined library into my project and running the program with a VM argument: --module-path /Library/Java/JavaVirtualMachines/javafx-sdk-11.0.2/lib --add-modules=javafx.controls. Now the program compiles but I bump into the issue described above.

This post describes the issue I'm having: https://discussions.apple.com/thread/7886329

import javafx.application.*;
import javafx.scene.*;
import javafx.stage.*;
import javafx.scene.layout.*;
import javafx.scene.control.*;

public class SimpleCalculator extends Application
{

    private Label firstValue;
    private Label secondValue;
    private Label sumLabel;

    public void start( Stage myStage) 
    {
        myStage.setTitle( "Simple Calculator");
        FlowPane rootNode = new FlowPane();        
        Scene myScene = new Scene( rootNode, 300, 200 );           

        Label firstValue = new Label( "First Value: ");            
        Label secondValue = new Label( "Second Value: ");          
        Label sumLabel = new Label( "Sum is: ");                   

        TextField firstField = new TextField();                    
        TextField secondField = new TextField();                   
        TextField sumField = new TextField();                      

        sumField.setEditable(false);                               

        rootNode.getChildren().addAll( firstValue, firstField, secondValue, secondField, sumLabel, sumField);
        myStage.setScene( myScene );                                                                                        
        myStage.show();                                                                                          
    }

    public static void main(String [] args)
    {
        launch( args );                                            
    }

}

Window pops and shows the labels and fields. This is not happening with my current code.

like image 675
Walter Gabriel Rivera Guzman Avatar asked Sep 20 '25 05:09

Walter Gabriel Rivera Guzman


1 Answers

I had this problem as did people associated with 3 other posts that I saw.

I disabled this option in run configurations of eclipse: Use the -XstartOnFirstThread argument when launching with SWT

It then worked perfectly

like image 197
SwiftMatt Avatar answered Sep 21 '25 21:09

SwiftMatt