Godot container not showing all lines

Godot Version

4.2

Question

Hello,
Trying to add elements to a scroll container via code, but it doesn’t work perfectly: specifically, if I add too many elements at once, the container won’t expand to show all of them. Then, if I add more elements, I can see the previously added ones, but not the newly added ones.

Is there a fix, so that all newly added elements are always shown?

For instance, I have this screen


Then, I add three lines by clicking the button, which shows this

(The last one is cut-off)

Finally, I add three more again, showing all the previous ones, but only two of the new ones

Is there a better way to add these elements in?
The code to add in looks like

	for line in dialog_lines.lines:

		var text_label = TextEdit.new()
		text_label.connect("text_changed", set_text(num_lines, text_label))

		text_label.custom_minimum_size = Vector2(100, 100)
		var idx_label = Label.new()

		text_label.text = line.text
		print(text_label.text)
		idx_label.text = str(num_lines)
		var parentControl = Control.new()
		var fileDialog = FileDialog.new()
		var fileDialogButton = Button.new()
		fileDialogButton.text = "Pick file"
		fileDialogButton.connect("button_down", func(): fileDialog.show())
		#parentControl.size=Vector2(0,300)
		#parentControl.position=Vector2(0,100+num_lines*75)

		$%TopLevelControl.add_child(parentControl)

		parentControl.add_child(idx_label)
		parentControl.add_child(text_label)
		parentControl.add_child(fileDialogButton)
		parentControl.add_child(fileDialog)
		fileDialog.size = Vector2(80, 400)
		fileDialog.root_subfolder = "res://"
		print(fileDialog.size)

		idx_label.position = Vector2(0, 0)
		text_label.position = Vector2(20, 0)
		fileDialogButton.position = Vector2(130, 0)

		if line.pic_str != null:
			print("Non-null!")
			var pic_area = TextureRect.new()
			fileDialog.connect("file_selected", make_handle_file_func(num_lines, pic_area))

			var new_pic = load(line.pic_str)
			pic_area.texture = new_pic
			pic_area.expand_mode = TextureRect.EXPAND_FIT_WIDTH
			pic_area.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT
			pic_area.size = Vector2(500, 500)
			pic_area.position = Vector2(200, 0)
			parentControl.add_child(pic_area)
		else:
			var pic_area = Container.new()
			parentControl.add_child(pic_area)
		#line.text="You're toast!"

		num_lines += 1

You can try using ScrollContainer.ensure_control_visible() after adding the child to the ScrollContainer. The description of the method tells you how to use it.