B4J Question How to add an Image to a "in code" created Button? - Daestrum (first post)    Oct 05, 2015   (2 reactions) try
...
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)
Mai B4J Question How to add an icon to a button via code - jmon (first post)    Aug 30, 2015   (2 reactions) Your code works just load the path of the image this way:
$"-fx-background-image: ${File.GetUri(File.DirAssets, "save.png")};"$
Otherwise, this method is my prefered one:
(Requires JavaObject):
Public Sub NodeSetImage(n As Node, ImageDir As String, ImageFileName As String, Width As Int, Height A B4J Question Lack of basic controls - jmon (first post)    Oct 12, 2016   (2 reactions) To set your button images, try this:
https://www.b4x.com/android/forum/threads/how-to-add-an-icon-to-a-button-via-code.57733/#post-363608
Then on the css of your button you need to set a padding:
CSSUtils.SetStyleProperty(btn, "-fx-padding", "4px")
Setting the padding with CSSUtils is the recommend B4J Question add image to button - Daestrum (first post)    May 07, 2016 After a quick test it looks like you need to add it to files in the designer and assets
43878
Hope this helps.
Oops I uploaded the wrong picture originally. (it was a background not a button) B4J Question Button with image - Erel (first post)    May 11, 2015   (1 reaction) You can use this code to add an ImageView to a button:
Sub SetGraphic(Btn As Button, Graphic As Node)
Dim jo As JavaObject = Btn
jo.RunMethod("setGraphic", Array(Graphic))
End Sub
Dim iv As ImageView
iv.Initialize("")
iv.SetImage(fx.LoadImage(File.DirAssets, "EffectNone.png"))
SetGraphic(but B4J Question B4J Button Images - Problems - stevel05 (first post)    Aug 10, 2022   (1 reaction) That is the expected behaviour. the set graphic method on a node adds the graphic within the target node, thereby stretching the target node to allow it to fit.
If you want to change the background image of the button, use the CSSUtils library.
Sub ButtonBOTTOM(BTN As Button)
CSSUtils.SetBack B4J Question Adding an icon via code - hanyelmehy    Jul 05, 2015 i use this to add icon to button
Sub AppStart (Form1 As Form, Args() As String)
...
'Define the button and add to the rootpane of the mainform
Dim btn As Button
btn.Initialize("btn")
btn.Tag = "This is my ImageButton"
MainForm.RootPane.AddNode(btn, 20,20,50, 50)
'Create the imageview and B4J Question [ABMaterial] Questions on understanding the framework... - Mashiane (first post)    Sep 28, 2016 Question 6: How to add Clickable Images on the ABMCard where buttons are?
The ABMCard can have numerous buttons in it. How do instead have clickable images. I have rounded the sections where I'd like to perhaps have clickable images.
Currently the code to add a button there is
card1.AddAction("BU B4J Tutorial [BANanoWebix] Lesson 5: Creating ToolBars - Mashiane (first post)    Jun 17, 2019   (2 reactions) Adding Buttons to the Toolbar
At the heart of a normal button is the Label/Value, the width & height, the type of button it is and the click event.
There is a variety of buttons that you can create: These are depicted in this enumeration class.
Public ButtonBase As String = ""
Public ButtonDa Share My Creation Creating javafx buttons with images - jkhazraji (first post)    Sep 27, 2023   (1 reaction) Dim btn as JavaObject
'
'
'
Dim imgPath As String =File.Combine(File.DirApp,"home32.png")
btn=(Me).As(JavaObject).RunMethod("createButtonWithImage",Array("Home",imgPath))
(Me).As(JavaObject).RunMethod("addListener",Array(btn))
Form1.RootPane.AddNode(btn,60,30,0,0)
Private Sub btn_click(msg As Strin Page: 1   2   3   4   5   6   7   Powered by ColBERT |