B4J Question Cross-platform development

shhammer5634

Member
Licensed User
Longtime User
I'm in the process of developing a B4J console application that is targeted for a Linux OS (an Ubuntu Digital Ocean droplet). The development is being done on a Windows box that is old enough to still have the Java SDK loaded and not OpenJDK. Even though the console application doesn't have any graphical UI, it still needs JFX. It generates some Excel spreadsheets and needs to set color for them. When I compile the application and move it to the droplet and try to run it, I get this error:

root@Ubuntuvpn:/usr/ePAL# java -jar ConsoleTest.jar
main._process_globals (java line: 3089)
java.lang.NoClassDefFoundError: javafx/stage/Window
at b4j.example.main._process_globals(main.java:3089)
at b4j.example.main.initializeProcessGlobals(main.java:3079)
at b4j.example.main.main(main.java:27)
Caused by: java.lang.ClassNotFoundException: javafx.stage.Window
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 3 more

root@Ubuntuvpn:/usr/ePAL# java -version
openjdk version "11.0.3" 2019-04-16
OpenJDK Runtime Environment (build 11.0.3+7-Ubuntu-1ubuntu218.04.1)
OpenJDK 64-Bit Server VM (build 11.0.3+7-Ubuntu-1ubuntu218.04.1, mixed mode, sharing)

I assume the issue is JFX in the OpenJDK environment.

My question: Is there a way to accomplish setting color without having JFX loaded (example)
B4X:
            DataRow.GetCell(0).CellStyle.ForegroundColor = fx.Colors.Cyan

I'm sure I'm being dense. All comments appreciated.
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
There is an error on your project, console aplications doesnt come with JavaFx preloaded or loaded, when you create a new project the IDE ask you if you want it to be with UI or NON UI, if you tell NON UI then no JFX.

Now you have to see how else change the foreground color (may be with HEX) to avoid using JFX
 
Upvote 0

shhammer5634

Member
Licensed User
Longtime User
There is an error on your project, console aplications doesnt come with JavaFx preloaded or loaded, when you create a new project the IDE ask you if you want it to be with UI or NON UI, if you tell NON UI then no JFX.

Now you have to see how else change the foreground color (may be with HEX) to avoid using JFX

Thanks Enrique, yes that's true. I added JFX to the non-hi project to handle the colors. This project was originally a ui project and I copied code into the new non-hi project. I was just hoping someone could point me in the right direction for setting colors without JFX.

Appreciate your response.
 
Upvote 0

shhammer5634

Member
Licensed User
Longtime User
I guess I should clarify a little more:

The non-ui console application runs fine on my windows platform with JFX defined and assigns colors etc. It's when it runs on the linux system that has OpenJDK11 installed that I run into trouble.

I made a simple little UI application so I could find out the values of the colors I needed by logging them. But when I try to assign one of those values in this line:
B4X:
            DataRow.GetCell(0).CellStyle.ForegroundColor = 0x00ffffff
I get this error:
Types do not match. (Warning #22)

I have tried to assign the value to a variable:
B4X:
            Dim Cyan as Int = 0x00ffffff
But the first line gives me the same error.

How do I assign a color value to a POI element like the one shown in the first code line without using JFX?

Thanks!
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
okey know i see that foregroundcolors was hardwired to JFX paint, i think you can change it with javaobject. i will try to come up with something
 
Upvote 0

shhammer5634

Member
Licensed User
Longtime User
Thanks Enrique.

I found a post on the forum that helped once I know what to ask for. This is a modified version of that code:

B4X:
Public Sub PaintToAwtColor(A As Int, R As Int, G As Int, B As Int) As Object
 
    Dim JO As JavaObject
    JO.InitializeNewInstance("java.awt.Color",Array(R,G,B,A))
 
    Return JO
End Sub

But now I'm running into other issues. It seems some of the libraries I'm using require JFX too. I'll have to go back to the drawing board.

Appreciate the help.
 
Upvote 0

shhammer5634

Member
Licensed User
Longtime User
Why are you using Swing? Why not create a regular UI app?
Hi Erel,

Because this will be running in a non-ui environment. All interactions with this application will be done through a remote client. The system this will be installed on is linux with no gui installed. Should I be using the regular UI and simply not define or display a form?

Thanks
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

OliverA

Expert
Licensed User
Longtime User
I'm guessing here that @shhammer5634 is using jPoi and he would like to do the spreadsheet manipulation in a non-ui application. Setting the color of a cell requires "Colors" which seems to be a JavaFX class. He's inquiring (at least that is what I get from reading the posts) if there is another way to set the colors without using that JavaFX class so JavaFX is not required for the non-ui app or if there is a way to include JavaFX in the non-ui app without issues (and how to do that).
 
Upvote 0

shhammer5634

Member
Licensed User
Longtime User
I'm guessing here that @shhammer5634 is using jPoi and he would like to do the spreadsheet manipulation in a non-ui application. Setting the color of a cell requires "Colors" which seems to be a JavaFX class. He's inquiring (at least that is what I get from reading the posts) if there is another way to set the colors without using that JavaFX class so JavaFX is not required for the non-ui app or if there is a way to include JavaFX in the non-ui app without issues (and how to do that).
Correct sir. I've been able to get around that for now though.
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
In working with jPoi, I use the UI version and don't show the MainForm. It looks and feels like a console app, but all Fx methods are available.
 
Upvote 0
Top