B4J Question javafx.scene.layout.BackgroundRepeat (HELP)

BeneBarros

Active Member
Licensed User
Longtime User
I have some images that are on the server.
I'm trying to put it deep in an AnchorPane. But this is returning me an error in "javafx.scene.layout.BackgroundRepeat".

"javafx.scene.layout.BackgroundSize" works.
"javafx.scene.layout.BackgroundPosition" works
"Javafx.scene.layout.BackgroundRepeat" does not work and returns the error below

setbackimage._initialize (java line: 65)
java.lang.RuntimeException: Constructor not found.
at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:94)
at b4j.example.setbackimage._initialize(setbackimage.java:65)
at b4j.example.main._testbackground(main.java:153)
at b4j.example.main._btaddremove_action(main.java:106)
at b4j.example.main._appstart(main.java:91)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at b4j.example.main.start(main.java:38)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)

B4X:
Sub Class_Globals
    Private fx As JFX
    Private wdt, hgt As Double
    Private BkgSize As JavaObject
    Private BkgPos As JavaObject
    Private BkgRepeatX As JavaObject   
    Private BkgRepeatY As JavaObject   
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(AP As AnchorPane)
    wdt = AP.Width
    hgt = AP.Height
    BkgSize.InitializeNewInstance("javafx.scene.layout.BackgroundSize", Array(wdt, hgt, True, True, True, False))
    BkgPos.InitializeNewInstance("javafx.scene.layout.BackgroundPosition", Array("LEFT", 10.0, True, "TOP", 0.0, True))
   
'    NO_REPEAT
'    The image Is placed once And Not repeated
'    REPEAT
'    The image Is repeated As often As needed To cover the area.
'    Round
'    The image Is repeated As often As will fit within the area.
'    SPACE
'    The image Is repeated As often As will fit within the area without being clipped And Then the images are spaced out To fill the area.   
'    BkgRepeatX.InitializeNewInstance("javafx.scene.layout.BackgroundRepeat", Array ("REPEAT"))
    BkgRepeatY.InitializeNewInstance("javafx.scene.layout.BackgroundRepeat", Array ("REPEAT"))
End Sub
 

stevel05

Expert
Licensed User
Longtime User
javafx.scene.layout.BackgroundRepeat is an Enum or a static class. It is not possible to create a new instance. You could initialize it as a static class and use getfield to get the required values, but this is not normally necessary. You can usually pass a string instead of an ENum variable. So whereever you want to use the REPEAT instance, just pass the string "REPEAT" and see if it works like that.
 
Upvote 0

BeneBarros

Active Member
Licensed User
Longtime User
javafx.scene.layout.BackgroundRepeat is an Enum or a static class. It is not possible to create a new instance. You could initialize it as a static class and use getfield to get the required values, but this is not normally necessary. You can usually pass a string instead of an ENum variable. So whereever you want to use the REPEAT instance, just pass the string "REPEAT" and see if it works like that.

would it be this??

BkgImg.InitializeNewInstance("javafx.scene.layout.BackgroundImage",Array(Img , "REPEAT", "NO_REPEAT" , BkgPos, BkgSize))

I'm going to change here.
 
Upvote 0

BeneBarros

Active Member
Licensed User
Longtime User
I gave up
I was unable to transfer Background mounted to AnchorPane.

I'll do it another way:
Save the image in DirTemp and do the following
APpane.Style = "-fx-background-image: url('" & File.GetUri(File.DirTemp, imageName) & "'); -fx-background-repeat: repeat-x;"
 
Upvote 0
Top