B4J Question [SOLVED] B4J TableView Column Alignment Error in Java versions higher than 8

Tirecs

Member
Licensed User
Longtime User
Hello forum members,
we use this function for setting the alignment of columns of a TableView in our B4J applications:
B4X:
'Possible Alignments: [ top-left | top-center | top-right | center-left | center | center-right | bottom-left | bottom-center | bottom-right | baseline-left | baseline-center | baseline-right ]
Sub SetColumnStyle(table As TableView, Index As Int, Style As String)
    Dim jo As JavaObject = table
    Dim Column As JavaObject = jo.RunMethodJO("getColumns", Null).RunMethod("get", Array(Index))
    Column.RunMethod("setStyle", Array(Style))
End Sub

In Java 8 all works fine, but with Java 11 and Java 14 an error is thrown:

The error happens in this generated Java code line:
Java:
_column = (anywheresoftware.b4j.object.JavaObject) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4j.object.JavaObject(), (java.lang.Object)(_jo.RunMethodJO("getColumns",(Object[])(anywheresoftware.b4a.keywords.Common.Null)).RunMethod("get",new Object[]{(Object)(_index)})));

Does anybody know how to avoid this error in higher Java versions than 8?

Thank you in advance
 

Daestrum

Expert
Licensed User
Longtime User
What version of the IDE are you using?
I just tried your code (in java 19, IDE v10.0) and it works normally.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
For completeness I tried your code (the commented out lines) and a single line version and both worked the same way.
B4X:
...
SetColumnStyle(TableView1,0,"-fx-alignment: center-right")
...

Sub SetColumnStyle(table As TableView, Index As Int, Style As String)
    'Dim jo As JavaObject = table
    'Dim Column As JavaObject = jo.RunMethodJO("getColumns", Null).RunMethod("get", Array(Index))
    'Column.RunMethod("setStyle", Array(Style))
    (table).As(JavaObject).RunMethodJO("getColumns",Null).RunMethodJO("get",Array(Index)).RunMethod("setStyle",Array(Style))
End Sub
 
Upvote 0

Tirecs

Member
Licensed User
Longtime User
I downloaded Java 19 and JavaFX Version 21 and tried it and got the same error:

 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Sorry, it's beyond me. I tried debug, release and compile to standalone package, and they all work as they should.
( I tried on java 19, 21 and 22)
 
Last edited:
Upvote 0

Tirecs

Member
Licensed User
Longtime User
Sorry, it's beyond me. I tried debug, release and compile to standalone package, and they all work as they should.
Thank you for your try, but are you sure that you start the app with Java 19. I have different Java version on my computer and when I just input Java in the console it starts with Java 8 and not with the other installed versions:


I also made a test app with just one TableView and the code. If i Run it in Java 8 all works fine and on Java 11 and 14 the error shows up:
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
I don't have any versions of java before 19 on this computer.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
If you run it in the IDE does it work?
 
Upvote 0

Tirecs

Member
Licensed User
Longtime User
You are right, if I start it directly in the IDE it works.
And I checked if the IDE starts it with JAVA 19 and it does.

But If i Start it with the command, it doesn't work:
C:\openjdk19\jdk-19.0.1\bin\java.exe --module-path C:\openjdk19\jdk-19.0.1\javafx\lib --add-modules=javafx.controls -jar C:\test_tableview\Objects\test_tableview.jar

Does it work if you start it with the command?
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
I think it's your command line that's incorrect.

Use the IDE to compile to standalone app, and then look at the command line in run_debug.bat, you will see there are major differences to your command line.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…