How to set application name at runtime - javafx

Whether I run my JavaFX application in the IDE or build and run the .jar, the application's name showing in the toolbar is basically the Main class :
I tried to build the artifact with IntelliJ and also with Maven ($ mvn clean package), but same result for both. I'm using JDK8 on Ubuntu.
Is there a way to change the application name/title?
Thanks.

As far as I know there is no programmatic way to set the application name in JavaFX. This can however be done when you package your application via the new jpackage tool (JDK 14).

Related

How to add javafx environment variable in Ubuntu now that the Oracle removed javafx from JDK?

I recently started learning javafx but now I came to know it was removed from the core JDK since java 11. I can't seem to find a way to compile javafx application. The import declaration is not working (I am using MVC design pattern). Is there a way to get around this?
I am using VS Code
Starting with Java 9, JavaFX was moved out of the JDK so that updates to JavaFX did not have to wait on the next JDK release (at least that's what I remember). When Ubuntu switched to JDK 11 from JDK 8, they added a new package "openjfx" that provides the JavaFX libraries.
So you have a couple of options to use JavaFX.
Install OpenJFX
sudo apt install openjfx libopenjfx-java
Setup Gradle Build
If you are using gradle to build, you can set it up to download whatever JavaFX version you want. Follow the instructions from openjfx for setting up a basic gradle configuration. The linked page has an example file you can start with.
You may also want to consider using Intellij Idea Community edition IDE instead of VS Code. I think VS Code is excellent and have used it for a couple of years now including for JavaFX development. I recently switched to Intellij and the features it provides for java development are step above VS Code. Plus it's provided as a snap so easy to install:
snap install intellij-idea-community --classic
So, about the environment variable. I'm guessing you are on Linux, so you have two ways of setting it:
A) set it for current session;
B) set it globally.
Option A: open the Terminal and execute export PATH_TO_FX=[absolute path to Javafx folder]/lib. This will create a variable for your current user for the current session only - you will have to execute it every time you boot your OS.
Option B: locate the file /etc/profile; then back it up; then open it for editing and add the export PATH_TO_FX="[absolute path to Javafx folder]/lib" line to the end of it. Save the file and restart your system. This way the variable will be preserved for all users permanently.
Finally, test the Javafx presence by launching your application jar - java -jar --module-path $PATH_TO_FX --add-modules javafx.controls,javafx.fxml your.jar (or launch your main class as shown in the documentation).

How to run javafx with maven desktop application from a jar file outside Netbeans 11 on my laptop or another ones?

I am working on Netbeans apache 11.1. I developed so many desktop programs using java and could run them almost on any computer. But when I moved to JavaFX technology with maven I wanted to redevelop almost the same desktop apps using JavaFX, and everything worked fine into Netbeans 11.1. The problem is when I want to jar my apps and distribute them outside of Netbeans they actually do not work.
I tried everything I did in the past (which worked just fine) for instance: adding Class-Path and setting Main-Class to manifest but still does not work. I searched through a lot of forums and sites but still cannot run my app outside of Netbeans.
My code is as any code combination of JavaFX, Maven, CSS, and FXML. Everything works just fine into Netbeans. The problem is outside of it.
Although I've added openjfx-12.0.2_windows-x64_bin-sdk to windows environment path, when I attempted to run jar that's been generated by Netbeans using cmd I just get this ERROR: javafx runtime components are missing, and are required to run this application. ANY HELP PLEASE?
I don't know if I'm understanding your problem right (if not I'm sorry).
Runnable JAR JavaFX
What once helped me, was create a new run configuration (in intellij) with the main class and the JRE. After that I created a Run Maven Goal with the command line
assembly:single

How do I export a tornadofx application?

I finished writing a little tornadofx app in IntelliJ CE and now want to export it as a single file which can be downloaded and launched by users. For now it would be sufficient to provide a single jar file. But it would be also great to know on how to export a self contained installer for OSX, Windows and Linux. Unfortunately I don't know how to do any of that. Can you help?
Have a look at the FxLauncher project, which is also from the creator of tornadoFX. FXLauncher allows you to easily distribute your javafx/tornadoFX application. The project provides a maven-plugin which allows you to generate a self containing javafx/tornadoFX application that you then publish to a web-server or common directory (e.g an internal app in your company network). After that you can generate native installers for Linux, OSX and Windows. The installer itself will only install a small app, which will know the location of your web-serve or directory. On startup it will download the latest deployed version of you application and run it.
Additional links:
GitHub-project
Introduction screen cast
Customizing update ui
In case you want a single jar file, you can export it as a regular Java program (not the JavaFX option in IntelliJ). You do this by creating and building an artifact.
Go to the Project Structure window, and from there select Artifacts
Click the "+" icon to create a new artifact, and select JAR > From modules with dependencies...
Select the main class and press OK
And that's it, the artifact has been set up, now, to generate jar file, just go to Build > Build Artifacts menu, and select the newly-made artifact, and the IntelliJ will generate the jar file in the "out" directory.
Not sure if this is the best solution, but it's what I've been using, and it works for me.

JAVAFX not being picked up in runtime from Spring STS with Java 8 on Mac

I've installed Java 8 and Spring STS on Mac. Running jjs from the command line works. However, when trying to create a new class in a Maven project in STS, the editor doesn't recognise the javafx.* package automatically.
Attached you'll find an example of an image showing that the only Label object suggested is the java.awt one.
Any idea on how I could solve this?
Regards,
M.
I think this is related to the settings of your project. If your project is created with an execution environment JavaSE-1.8, this execution environment doesn't have the javafx API defined as accessible and you would need to manually allow that. If you choose the 1.8 JRE (as a JRE, not an execution environment) in your project settings, the JavaFX API is accessible and works nicely in content-assist, quick fix, etc. This is at least the case if you create a standard Java project.

How can I use the same buildscript for Flash Builder 4 and Ant/Mvn?

I'm setting up a build system for a Flash Builder 4 (Flex 4) based project; and I'm struggling to get a setup that compiles in the IDE the same as it does from the command line on the build server.
I come from a C# background; and my expectation is that I'll be able to create a "solution" with a collection of "projects" that I can compile from the IDE, or from the command line on the build server.
The best I've managed sofar is 2 separate build "scripts", a custom ant script for the build server, and the default Flash Builder IDE config based on a workspace; but this is making my DRY daemons jump around in fury.
Please can someone point me in the right direction :)
If you use Maven and flex-mojos for your command line builds, then you can use the flexbuilder mojo to generate the Eclipse project files from your Maven build scripts. I'm sure there are some rough edges with the process, but at least it's DRY.
You might also check out IntelliJ IDEA. It can open the Maven project directly, and will create the Flex facets and configuration from the Maven build script. It will auto-detect when the pom.xml file changes, and prompt for re-import (which is nice). You can enable auto-import, too. The down side is that it doesn't have the profiler or nice GUI editor that Flash Builder has.

Resources