Skip to content

NewBorder

It Creates a container with optional top, bottom, left, and right objects around a central content widget in Fyne.

To demostrate Border usage, I have created a dashboard example with a sidebar, menu, and a status bar.

Show Code
package main
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
)
func main() {
myApp := app.New()
myWindow := myApp.NewWindow("Border Layout")
// Status bar (bottom)
statusBar := widget.NewLabel("Ready")
// Central content placeholder
centerLabel := widget.NewLabel("Welcome to the Dashboard!")
// Function to update center content
updateContent := func(text string) {
centerLabel.SetText(text)
statusBar.SetText("Viewing: " + text)
}
// Sidebar buttons (left)
sidebar := container.NewVBox(
widget.NewButton("Dashboard", func() { updateContent("Welcome to the Dashboard!") }),
widget.NewButton("Settings", func() { updateContent("Here are your Settings.") }),
widget.NewButton("Profile", func() { updateContent("This is your Profile.") }),
widget.NewButton("Reports", func() { updateContent("View Reports here.") }),
)
// Top menu
menu := fyne.NewMainMenu(
fyne.NewMenu("File",
fyne.NewMenuItem("New", func() {}),
fyne.NewMenuItem("Quit", func() { myApp.Quit() }),
),
fyne.NewMenu("Help",
fyne.NewMenuItem("About", func() { updateContent("This is a Fyne app example.") }),
),
)
myWindow.SetMainMenu(menu)
// Main layout with NewBorder
layout := container.NewBorder(
nil, // Top handled by menu
statusBar, // Bottom
sidebar, // Left
nil, // Right
centerLabel, // Center
)
myWindow.SetContent(layout)
myWindow.Resize(fyne.NewSize(600, 400))
myWindow.ShowAndRun()
}