B4J Question How to clone a label, to the right of another label?

B4JExplorer

Active Member
Licensed User
Longtime User
Hi,

I have three labels horizontally one after the other, defined in the Internal Designer, on top of an edit box. Programmatically, there is an extra label defined, which I would like to place to the right of the label currently on the right.

B4X:
	Private lbl_Test As Label
	
	lbl_Test.Initialize( "label" )
	lbl_Test.Visible = True
	lbl_Test.Font = lbl_Item_001.Font
	lbl_Test.Text = "test label"
	lbl_Test.Enabled = True
	lbl_Test.TextColor = lbl_Item_001.TextColor
	lbl_Test.Style = lbl_Item_001.Style

	MainForm.RootPane.AddNode( lbl_Test, lbl_Item_003.Left + lbl_Item_003.Width + 5, lbl_Item_001.Top, lbl_Item_001.Width, lbl_Item_001.Height )
	
	MainForm.Show

, but when the new label is displayed, it shows up at the same beginning left position as the last label lbl_item_003. I'd like it to show up immediately to the right of the right side of 003,
 

stevel05

Expert
Licensed User
Longtime User
This depends on where you are defining the label, if it is in (or called directly from) the appstart sub, then there is a good chance that the layout is not completely laid out when you are reading the position of the existing label.

You should use the PrefWidth in preference to the Width method, and try putting it in a separate sub and call it using callsubdelayed.
 
Upvote 0

B4JExplorer

Active Member
Licensed User
Longtime User
This depends on where you are defining the label, if it is in (or called directly from) the appstart sub, then there is a good chance that the layout is not completely laid out when you are reading the position of the existing label.

You should use the PrefWidth in preference to the Width method, and try putting it in a separate sub and call it using callsubdelayed.
You're right, it was a matter of timing. I moved the AddNode after the .Show, and it looks good.

Thank you, sir.
 
Upvote 0
Top