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:
main._setcolumnstyle (java line: 1402)
java.lang.IllegalAccessException: class anywheresoftware.b4j.object.JavaObject cannot access class com.sun.javafx.collections.ObservableListWrapper (in module javafx.base) because module javafx.base does not export com.sun.javafx.collections to unnamed module @7faa412c
at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:361)
at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:591)
at java.base/java.lang.reflect.Method.invoke(Method.java:558)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
at pd.baurecs.main._setcolumnstyle(main.java:1402)
at pd.baurecs.m05_frmdokumente._show(m05_frmdokumente.java:2056)
at pd.baurecs.main._m00_pangroup_mouseclicked(main.java:866)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
at anywheresoftware.b4j.objects.NodeWrapper$1.handle(NodeWrapper.java:109)
at anywheresoftware.b4j.objects.NodeWrapper$1.handle(NodeWrapper.java:1)
at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
at javafx.graphics/javafx.scene.Scene$ClickGenerator.postProcess(Scene.java:3564)
at javafx.graphics/javafx.scene.Scene$ClickGenerator.access$8200(Scene.java:3492)
at javafx.graphics/javafx.scene.Scene$MouseHandler.process(Scene.java:3860)
at javafx.graphics/javafx.scene.Scene$MouseHandler.access$1200(Scene.java:3579)
at javafx.graphics/javafx.scene.Scene.processMouseEvent(Scene.java:1849)
at javafx.graphics/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2588)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:397)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:434)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:390)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:433)
at javafx.graphics/com.sun.glass.ui.View.handleMouseEvent(View.java:556)
at javafx.graphics/com.sun.glass.ui.View.notifyMouse(View.java:942)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)

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

Tirecs

Member
Licensed User
Longtime User
B4J_Version.png
 
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
1701250327423.png
 
Upvote 0

Tirecs

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

main._setcolumnstyle (java line: 1402)
java.lang.IllegalAccessException: class anywheresoftware.b4j.object.JavaObject cannot access class com.sun.javafx.collections.ObservableListWrapper (in module javafx.base) because module javafx.base does not export com.sun.javafx.collections to unnamed module @240412dd
at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:420)
at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:709)
at java.base/java.lang.reflect.Method.invoke(Method.java:569)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
at pd.baurecs.main._setcolumnstyle(main.java:1402)
at pd.baurecs.m05_frmdokumente._show(m05_frmdokumente.java:2056)
at pd.baurecs.main._m00_pangroup_mouseclicked(main.java:866)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
at anywheresoftware.b4j.objects.NodeWrapper$1.handle(NodeWrapper.java:109)
at anywheresoftware.b4j.objects.NodeWrapper$1.handle(NodeWrapper.java:1)
at [email protected]/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at [email protected]/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:232)
at [email protected]/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:189)
at [email protected]/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at [email protected]/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at [email protected]/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at [email protected]/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at [email protected]/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at [email protected]/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at [email protected]/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at [email protected]/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at [email protected]/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at [email protected]/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at [email protected]/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at [email protected]/javafx.event.Event.fireEvent(Event.java:198)
at [email protected]/javafx.scene.Scene$ClickGenerator.postProcess(Scene.java:3688)
at [email protected]/javafx.scene.Scene$MouseHandler.process(Scene.java:3993)
at [email protected]/javafx.scene.Scene.processMouseEvent(Scene.java:1890)
at [email protected]/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2708)
at [email protected]/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:411)
at [email protected]/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:301)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at [email protected]/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:450)
at [email protected]/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:424)
at [email protected]/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:449)
at [email protected]/com.sun.glass.ui.View.handleMouseEvent(View.java:551)
at [email protected]/com.sun.glass.ui.View.notifyMouse(View.java:937)
at [email protected]/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at [email protected]/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:185)
at java.base/java.lang.Thread.run(Thread.java:1589)
 
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:
Unbenannt2.png


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:
Unbenannt.png
 
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
Top