B4J Question JavaFX resizing problem with library.

keirS

Well-Known Member
Licensed User
Longtime User
I have wrapped the HBox pane which seems to be working fine apart from the resize.





Resizing of the controls contained by the HBox works fine.
If I set the HGrow of the textfield to "SOMETIMES" it expands to fill the space as expected.



I set the MinWidth property of the HBox to 200 and resize the form and the HBox doesn't resize.




B4X:
#Region Project Attributes 
    #MainFormWidth: 600
    #MainFormHeight: 200
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Dim ABox As HBox
    Dim Btn1 As Button
    Dim Btn2 As Button
    Dim Btn3 As Button
    Dim txt1 As TextField
    Dim PN1 As Pane
    Dim I As Image
    Dim JO As JavaObject
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.Show
    Btn1.Initialize("Btn_1")
    Btn2.Initialize("Btn_2")
    Btn3.Initialize("Btn_3")
    txt1.Initialize("txt_1")
    PN1.Initialize("PN1")
    ABox.Initialize("Hbox")
    ABox.setPadding(10,10,10,10)
    ABox.Spacing = 10
    ABox.FillHeight = True
    ABox.PrefWidth = 300
    txt1.PrefWidth = 50
   

    Btn1.Text = "Press Me"
    ABox.AddNode(Btn1)
    ABox.AddNode(Btn2)
    ABox.AddNode(Btn3)
    ABox.AddNode(txt1)
    ABox.setHgrow(txt1,"SOMETIMES")

    ABox.MinWidth =200
    MainForm.RootPane.AddNode(ABox,10,10,400,40)
    Log(ABox.MinWidth)

   
    MainForm.RootPane.AddNode(PN1,12,100,400,40)
    CSSUtils.SetBackgroundColor(ABox,fx.Colors.DarkGray)
    CSSUtils.SetBackgroundColor(PN1,fx.Colors.DarkGray)
   
   
   
   
End Sub

'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Sub Btn_1_MouseClicked (EventData As MouseEvent)
    Dim FN As String = Rnd(1,1000000) & ".png"
    I = MainForm.RootPane.Snapshot
    Dim Out As OutputStream = File.OpenOutput("C:\_2",FN,False)
    I.WriteToStream(Out)
    Out.Close
    Log("Hbox Min Width: " & ABox.MinWidth)
    Log("HBox Width: " & ABox.Width)
    Log("MainForm Width: " & MainForm.Width)
    Log("RootPane Widht:" &MainForm.RootPane.Width)
   
   
End Sub

I am obviously missing something but I am not sure what? I thought resizing was controlled by the parent pane and setting a minWidth would tell the parent what the minimum width of a node could be.


Output of the log from the last image after pressing the Press Me button:

B4X:
Hbox Min Width: 200
HBox Width: 400
MainForm Width: 343
RootPane Widht:343
 

keirS

Well-Known Member
Licensed User
Longtime User
Probably not clear about what I was asking. My wrap is in Java. I want to add my node to the list maintained by B4J for resizing. I guess I could add my own ChangeListener to the width and height properties of the nodes parent but I think B4J must already have a mechanism for doing that?
 
Upvote 0

keirS

Well-Known Member
Licensed User
Longtime User
I have had a further play about with this and set the Anchors for the HBox. However the resizing takes no account of the HBox's minWidth property.



B4X:
MainForm.RootPane.SetLeftAnchor(ABox,10)
MainForm.RootPane.SetTopAnchor(ABox,10)
MainForm.RootPane.SetBottomAnchor(ABox,540)
MainForm.RootPane.SetRightAnchor(ABox,200)

Logs:
B4X:
Hbox Min Width: 200
HBox Width: 171
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Note that anchors from AnchorPane are mostly not used in B4J.

See the custom views tutorial: https://www.b4x.com/android/forum/t...with-enhanced-designer-support.62488/#content
You need to handle the parent resize event.
In B4J the layout is managed from the top to the bottom. This means that the child views know their parent size and they then resize themselves based on that size.
The parent doesn't know the child views sizes.
 
Upvote 0

keirS

Well-Known Member
Licensed User
Longtime User
i wasn't going to bother with designer support as I don't use the designer much. However I will have a look at the example source code.
 
Upvote 0

keirS

Well-Known Member
Licensed User
Longtime User
I highly recommend you to learn to work with the designer. It is true in B4A and it is especially true in B4J and B4i where the designer handles the resize events for you.

A lot of the stuff I do requires dynamically generated content. I read records from a DB that tell me which fields to generate and display and the query's to run to populate them along with the rules for validation and updates.
 
Upvote 0

keirS

Well-Known Member
Licensed User
Longtime User
Well I got it working how I wanted.

Start:



Resized:



Lock resizing to the minimum width of the HBox. The pane continues to shrink but the HBox stays at it's minimum width.

 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…