Reputation: 41
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.
Upvotes: 4
Views: 9110
Reputation: 1
Use JavaFX 17.0.2
Compile
javac -d . --module-path E:\javafx-sdk-17.0.2\lib --add-modules javafx.controls,javafx.fxml Shape_Example.java
Run
java --module-path E:\javafx-sdk-17.0.2\lib --add-modules javafx.controls,javafx.fxml rame.Shape_Example
Upvotes: 0
Reputation: 405
Had this issue in IntelliJ
My problem was a simple mistake. When adding a connection to my database I added these lines to the main function in Main class.
JDBC.openConnection();
JDBC.closeConnection();
But I also unknowingly removed:
launch();
So even though you might not have a database in your application, make sure that launch() is still in the main function
Upvotes: 0
Reputation: 1029
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
Upvotes: 22