B4J Question Programatically set node anchors

TorontoJim

Member
Licensed User
Longtime User
I'm creating my first custom view using a list view.

I have it to the point it's loading and functional, but I can't figure out how to set the width and height anchors to "BOTH."

From what I've read, this can't be done. But I may not have read enough. What is the trick to making a programmatically added node change size along with the container it's in (even if that's just the plain form)?

This is how I am doing it for now, with set sizes. But I want it to be resizable with whatever the user puts it in.

B4X:
Public Sub DesignerCreateView (Base As Pane, Lbl As Label, Props As Map)
    mBase = Base
    ExplorerDropDown.Initialize("ExplorerDropDown")
    ExplorerDropDown.PrefHeight = 20.00
    Base.AddNode(ExplorerDropDown, 3,3,300, -1)
    ExplorerDropDown.Style = "-fx-font-size: 12;"
    ExplorerDropDown.Editable = True
   
    ExplorerWindow.Initialize("ExplorerWindow")
    Base.AddNode(ExplorerWindow, 3,29, 300,450)
    ExplorerWindow.Style = "-fx-font-size: 12;"
 

TorontoJim

Member
Licensed User
Longtime User
I figured it out on my own.

I put the two nodes in an anchor pane node and then resized that when Base_Resize was raised.

B4X:
Public Sub DesignerCreateView (Base As Pane, Lbl As Label, Props As Map)
    mBase = Base
    anchorEW.Initialize("aew")
    ExplorerDropDown.PrefHeight = 20.00
    ExplorerDropDown.Style = "-fx-font-size: 12;"
    ExplorerDropDown.Editable = True
    anchorEW.AddNode(ExplorerDropDown, 3, 3, -1, -1)
    anchorEW.SetAnchors(ExplorerDropDown, 3, 3, 3, -1)
   
    ExplorerWindow.Style = "-fx-font-size: 12;"
    anchorEW.AddNode(ExplorerWindow, 3, 29, -1, -1)
    anchorEW.SetAnchors(ExplorerWindow, 3, 29, 3, 3)
    Base.AddNode(anchorEW, 0,0,-1, -1)
    CallSubDelayed2(Me, "AfterLoadLayout", Props)
End Sub

Private Sub Base_Resize (Width As Double, Height As Double)
    ExplorerDropDown.PrefWidth = Width
    ExplorerWindow.PrefWidth = Width
    ExplorerWindow.PrefHeight = Height
End Sub
 
Upvote 0
Top