B4J Question [Solved] PrefHeight in Class not affect

rraswisak

Active Member
Licensed User
Longtime User
Hi every body

I have a CAlert class with this code:

B4X:
Sub Class_Globals
   Private fx As JFX
   Dim mParent As Form
   Private Label1 As Label
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(Parent As Form)
   mParent = Parent
End Sub

Sub Show
   Dim xui As XUI
   Dim p As B4XView  = xui.CreatePanel("")
   p.LoadLayout("1")
   mParent.RootPane.AddNode(p,0,0,mParent.Width, mParent.Height)
   Label1.PrefHeight = 100 '<-- no affect
End Sub

Then i call the class from Main module:

B4X:
Sub MainForm_MouseClicked (EventData As MouseEvent)
   Dim c As CAlert
   c.Initialize(MainForm)
   c.Show
End Sub

In designer, Label1 height was 30. but when i want to change at runtime with different value it does not affect, why ?

Thanks
 

Tayfur

Well-Known Member
Licensed User
Longtime User
B4X:
Sub Class_Globals
   Private fx As JFX
   Dim mParent As Form
   Private Label1 As Label
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(Parent As Form)
   mParent = Parent
End Sub

Sub Show
   'Dim xui As XUI
   'Dim p As B4XView  = xui.CreatePanel("")
   'p.LoadLayout("1")
  ' mParent.RootPane.AddNode(p,0,0,mParent.Width, mParent.Height)
mParent.RootPane.LoadLayout("1")  
Label1.PrefHeight = 100 '<-- no affect
End Sub
 
Upvote 0

rraswisak

Active Member
Licensed User
Longtime User
Thank you Tayfur for your repply, your code was correct, but in my case CAlert class will act as (my own version) custom dialog, whether user click a button then the alert will be closed (remove from its parent) thats why i declare p variable.

I have done this way from B4A and its work, but not in B4J
 
Upvote 0

rraswisak

Active Member
Licensed User
Longtime User
okay, i think i solve the problem with sleep function addition
B4X:
Sub Show
   Dim xui As XUI
   Dim p As B4XView  = xui.CreatePanel("")
   p.LoadLayout("1")
   mParent.RootPane.AddNode(p,0,0,mParent.Width, mParent.Height)
   Sleep(0)
   Label1.PrefHeight = 100 '<-- now its work
End Sub
 
Upvote 0
Top