B4J Question How to add an Image to a "in code" created Button?

Cableguy

Expert
Licensed User
Longtime User
I guess the title says it all, how to add an image to a button that was created in code?
 

Daestrum

Expert
Licensed User
Longtime User
try
B4X:
...
     Dim iv As ImageView
     Dim im As Image
     Dim b As Button
     iv.Initialize("")
     im.Initialize("","your image for the button.png")
     iv.SetImage(im)
     b.Initialize("b1")
     asJO(b).RunMethod("setGraphic",Array(iv))
     MainForm.RootPane.AddNode(b,10,10,-1,-1)
     MainForm.Show
End Sub
Sub asJO(o As JavaObject) As JavaObject
      Return o
End Sub
 
Upvote 0
Top