Box

The box widget is a simple horizontal or vertical container that uses the box layout to lay out the child components. You can pass the objects to include in the container.NewHBox() or container.NewVBox() constructor functions.

It is also possible to add items to a box widget after it is created using Add() (to after the existing content) or remove items using Remove().

Example Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package main

import (
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/widget"
)

func main() {
	myApp := app.New()
	myWindow := myApp.NewWindow("Entry Widget")

	content := container.NewVBox(
		widget.NewLabel("The top row of the VBox"),
		container.NewHBox(
			widget.NewLabel("Label 1"),
			widget.NewLabel("Label 2"),
		),
	)

	content.Add(widget.NewButton("Add more items", func() {
		content.Add(widget.NewLabel("Added"))
	}))

	myWindow.SetContent(content)
	myWindow.ShowAndRun()
}
< 2/2 >