B4J Question [BANano] BNanoElement.SetStyle doesn't work for me

Kiffi

Well-Known Member
Licensed User
Longtime User
Hello,

i try to set the style for a BNanoElement with SetStyle() but the code taken from the documentation doesn't work for me:

  • SetStyle (json As java.lang.Object) As void
    Sets the style of the target BANanoElement.

    example:

    <code>
    dim json as JSONGenerator
    json.initialize("{ background: 'green', display: 'none', 'border-radius': '5px' }")
    BANano.Get("#someid").SetStyle(json)
    </code>

src\b4j\example\main.java:100: error: incompatible types: String cannot be converted to MyMap

And it is not possible to initialize the JSONGenerator with a Map because BNano doesn't support it.

Thanks in advance & Greetings ... Peter (B4J: 6.80 B1 / Json: 1.10 / BNano: 1.03)
 

alwaysbusy

Expert
Licensed User
Longtime User
I think it is just the example that is wrong (I copied the json style from another page if I recall correct):

this should work:

B4X:
dim json as JSONGenerator
json.initialize($"{"background-color": "red", "border-radius": "5px"}"$)
BANano.GetElement("#someid").SetStyle(json)

As for JSONGenerator not supporting a Map, this would be a bug, as it should (with the Initialize method)
 
Upvote 0

Kiffi

Well-Known Member
Licensed User
Longtime User
ok, i figured it out. I have to call SetStyle() with a String:

B4X:
BANano.GetElement("body").Append("<div id='myDiv'></div>")
Dim myDiv As BANanoElement
myDiv = BANano.GetElement("#myDiv")
Dim myJson As String = $"{ "width": "200px", "height": "200px", "background": "green", "border-radius": "5px" }"$
myDiv.SetStyle(myJson)

Greetings ... Peter
 
Upvote 0
Top