0

I'm wondering why my programs in Swing can run at every machine which have Java installed, but JavaFX programs not. If I want to run my program in JavaFX i have to copy some JavaFX library files to JDK folder like here. The problem is: I don't want to force people to move some files into any folder! I want them to be able run the program just by clicking it and nothing else! I want to make it simple. Other Programs in Java don't force me to do that so how can i make my program like others? What should i do? Here are some example of code.

Main.java

package fxTutorial;

public class Main {
    public static void main(String[] args){
        Demo.main(args);
    }
}

Demo.java

package fxTutorial;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class Demo extends Application implements EventHandler {

    Button button = new Button();
    public static void main(String[] args){
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        primaryStage.setTitle("Application");
        button.setText("Button");
        button.setOnAction(this);

        StackPane stackPane = new StackPane();
        stackPane.getChildren().add(button);
        Scene scene = new Scene(stackPane,400,500);
        primaryStage.setScene(scene);
        primaryStage.show();

    }


    @Override
    public void handle(Event event) {
        if(event.getSource()==button)
            //Do something, like background changing - Whatever
    }
}

module-info.java

module Demo {
    requires javafx.fxml;
    requires javafx.controls;

    opens fxTutorial;
}
  • 1
    If you are depolying a program, you should be able to create a jar that has everything needed. – SedJ601 Jul 07 '19 at 16:04
  • 1
    https://openjfx.io/openjfx-docs/ – SedJ601 Jul 07 '19 at 16:12
  • Swing is included in the JDK. JavaFX was removed from OracleJDK in Java 11 and was never part of OpenJDK distributions. Some distributions, such as [ZuluFX](https://www.azul.com/downloads/zulu/zulufx/), still include OpenJFX. Also, note that JavaFX uses platform-specific native libraries. – Slaw Jul 07 '19 at 16:35
  • 1
    Some of these questions may help: https://stackoverflow.com/questions/53453212/ | https://stackoverflow.com/questions/52653836/ | https://stackoverflow.com/questions/54063041/ | https://stackoverflow.com/questions/52569724/ | https://stackoverflow.com/questions/53450011/ – Slaw Jul 07 '19 at 16:37
  • Thanx, it helped! But i downloaded Java 1.8 and compiled my programs on this version. Because for some reason Oracle is providing this version to end-users. https://java.com/pl/download/ Normal pc user will just type Java in Google search and he will end up with Java 1.8. But I was programming in Java 11. 8 is pretty old version now. Someone know why Oracle is doing that? To prevent situation when someone won't update on time their program to the newest version of Java? I just want to make my program as simple in running as it can be. Telling users to search for Java 11 is not simple. – Adrian Stypiński Jul 09 '19 at 10:19
  • Ok i found this: https://dzone.com/articles/when-will-java-11-replace-java-8-as-the-default-ja If it's still valid it explains a lot. So... I guess for now I have to focus on Java 11 but have in mind that users still have Java 1.8 and I have to compile programs for them too – Adrian Stypiński Jul 09 '19 at 10:33
  • Java, at least for desktop applications, seems to be moving towards self-contained applications for deployment (i.e. the JRE is embedded in the application). Doing this means one doesn't have to worry if the end user has the correct Java version installed. Java 13 has an early-access version of the `jpackage` tool available which can create executables/installers for Windows, Mac, and Linux, I believe. – Slaw Jul 09 '19 at 14:30

0 Answers0