Bug? Adding Button via Code to a Pane has fixed width/height

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,

when adding buttons to a pane using code below, the Buttons Width and Height are fixed and not set acoording the code.
Is this a bug or do I miss something in the code?

B4X:
Sub CreateCharMatrix
    Dim btn As Button
    btn.Initialize("btn")
    btn.Tag = "1"
    MainForm.RootPane.AddNode(btn, 20, 20, 10, 10)

    Dim btn As Button
    btn.Initialize("btn")
    btn.Tag = "2"
    MainForm.RootPane.AddNode(btn, 20, 80, 20, 20)
End Sub

 

Roycefer

Well-Known Member
Licensed User
Longtime User
It looks like there's a minimum width and height for Buttons:
B4X:
For j = 1 To 25
    For i = 1 To 25
        Dim b As Button
        b.Initialize("b")
        MainForm.RootPane.AddNode(b, i*30, j*30, i, j)
    Next
Next
 

Cableguy

Expert
Licensed User
Longtime User
It seems that JavaFX nodes have a minimum size. I had a similar issue with TextArea.
Also note that, adding the node to the parent pane sets it to the "preferred" values of Height and Width, which can be different from the Height/Width intended
 

rwblinn

Well-Known Member
Licensed User
Longtime User
Thanks all for your hints.
Tried several solutions, but ended up, after the node has been created, using the API call setMinSize as @BeneBarros suggested.

B4X:
'define the button and add to the rootpane of the mainform
Dim btn As Button
btn.Initialize("btn")
btn.Text = "Button 1"
'h and w must have initial value > 0
MainForm.RootPane.AddNode(btn, 20,20, 1, 1)
Dim jo As JavaObject = btn
Dim h As Double = 15.0
Dim w As Double = 15.0
jo.RunMethod("setMinSize", Array(h, w))

BTW: Look here if you want to know why I had asked.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…