B4J Question How to send Colors through subs?

Midimaster

Active Member
Licensed User
I would like to send a Jfx-Color to a sub where I asign it to a View, but it looks like the type COLORS in not known in the sub. What do I do wrong?


B4X:
'this works:
MyButton.TextColor=jfx.colors.red

'this not:
SendColor(jfx.colors.red)

Sub SendColor(Color as Colors)
    MyButton.TextColor=Color
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
jfx.Colors.Red return an INT-Value and MyButton.TextColor needs an Int-Value.

B4X:
Sub SendColor(Color as Int)
    MyButton.TextColor=Color
End Sub

PS: Sure this is an Android question?
 
Upvote 0

Midimaster

Active Member
Licensed User
I already tried also this, but it ends up with a crash
B4X:
Log("Spurrow reset color " & index )
SetTextColor(index,Jfx.Colors.yellow)


Sub SetTextColor(index As Int, Color As Int   )
    StudioSpurItem.TextColor=Color
End Sub
Spurrow reset color 0
Fehler in Zeile: 865 (Main)
java.lang.NumberFormatException: For input string: "0xffff00ff"
at java.base/jdk.internal.math.FloatingDecimal.parseHexString(FloatingDecimal.java:2082)
at java.base/jdk.internal.math.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1870)
at java.base/jdk.internal.math.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
at java.base/java.lang.Double.parseDouble(Double.java:543)
at anywheresoftware.b4a.BA.ObjectToNumber(BA.java:395)
at b4j.example.main._spurlabelcolorreset(main.java:1679)
at b4j.example.main._metrolbl_mousepressed(main.java:1634)
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.shell.Shell.runMethod(Shell.java:632)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at jdk.internal.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
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:91)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
at anywheresoftware.b4j.objects.NodeWrapper$2.handle(NodeWrapper.java:121)
at anywheresoftware.b4j.objects.NodeWrapper$2.handle(NodeWrapper.java:1)
....
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Are you asking for B4A or B4J?
jFX.Colors.Yellow is for B4J and is a Paint object!

In B4A, this works.
SetTextColor(index, Colors.Yellow)

Suggestion: use B4XViews, it will make your life easier.
xui colors are integers for all three platforms.
 
Upvote 0

Midimaster

Active Member
Licensed User
oh ! sorry I posted it in B4A. but I need it for B4J

xui colors are integers for all three platforms.
Ah, did'nt know that way! Now it works:

B4X:
        SetTextColor(1,xui.Color_Red)

As I transscripe my B4A-project to B4J I was happy only need to add a jfx. in front of all my color commands. But now I see it was the wrong way.
 
Last edited:
Upvote 0
Top