[GH-ISSUE #957] Adding a border removes the content of the element #701

Closed
opened 2026-03-04 01:07:07 +03:00 by kerem · 1 comment
Owner

Originally created by @justlunix on GitHub (Mar 10, 2024).
Original GitHub issue: https://github.com/rivo/tview/issues/957

Hi, I have a problem where when I set the border on an element, the content won't be displayed anymore. I'm probably doing something wrong, so maybe someone can help me.

I think it's because the SetBorder returns a Box, so it "forgets" the other non-box settings. But I don't know how to fix it.

func Welcome() tview.Primitive {
	return tview.NewFlex().
		AddItem(nil, 0, 1, false).
		AddItem(tview.NewFlex().SetDirection(tview.FlexRow).
			AddItem(nil, 0, 1, false).
			AddItem(connectionList(), 0, 1, false).
			AddItem(nil, 0, 1, false), 0, 2, false).
		AddItem(nil, 0, 1, false)
}

func hasConnections() bool {
	return true
}

func connectionList() tview.Primitive {
	if hasConnections() {
		return tview.NewList().
			AddItem("List item 1", "Some explanatory text", 'a', nil).
			AddItem("List item 2", "Some explanatory text", 'b', nil).
			AddItem("List item 3", "Some explanatory text", 'c', nil).
			AddItem("List item 4", "Some explanatory text", 'd', nil).
			AddItem("Quit", "Press to exit", 'q', nil).
			SetBorder(true).
			SetTitle("Connections")

	} else {
		return tview.NewTextView().
			SetText("No connections found. Press 'a' to add a connection.").
			SetBorder(true).
			SetTitle("Connections")
	}
}

This will result in:
image

If I remove the border it will display like this:

if hasConnections() {
		return tview.NewList().
			AddItem("List item 1", "Some explanatory text", 'a', nil).
			AddItem("List item 2", "Some explanatory text", 'b', nil).
			AddItem("List item 3", "Some explanatory text", 'c', nil).
			AddItem("List item 4", "Some explanatory text", 'd', nil).
			AddItem("Quit", "Press to exit", 'q', nil)
	}
image
Originally created by @justlunix on GitHub (Mar 10, 2024). Original GitHub issue: https://github.com/rivo/tview/issues/957 Hi, I have a problem where when I set the border on an element, the content won't be displayed anymore. I'm probably doing something wrong, so maybe someone can help me. I think it's because the SetBorder returns a Box, so it "forgets" the other non-box settings. But I don't know how to fix it. ```go func Welcome() tview.Primitive { return tview.NewFlex(). AddItem(nil, 0, 1, false). AddItem(tview.NewFlex().SetDirection(tview.FlexRow). AddItem(nil, 0, 1, false). AddItem(connectionList(), 0, 1, false). AddItem(nil, 0, 1, false), 0, 2, false). AddItem(nil, 0, 1, false) } func hasConnections() bool { return true } func connectionList() tview.Primitive { if hasConnections() { return tview.NewList(). AddItem("List item 1", "Some explanatory text", 'a', nil). AddItem("List item 2", "Some explanatory text", 'b', nil). AddItem("List item 3", "Some explanatory text", 'c', nil). AddItem("List item 4", "Some explanatory text", 'd', nil). AddItem("Quit", "Press to exit", 'q', nil). SetBorder(true). SetTitle("Connections") } else { return tview.NewTextView(). SetText("No connections found. Press 'a' to add a connection."). SetBorder(true). SetTitle("Connections") } } ``` This will result in: <img width="822" alt="image" src="https://github.com/rivo/tview/assets/66276367/ee6a1e0a-3000-4fb6-bad3-7c86c5338c89"> If I remove the border it will display like this: ```go if hasConnections() { return tview.NewList(). AddItem("List item 1", "Some explanatory text", 'a', nil). AddItem("List item 2", "Some explanatory text", 'b', nil). AddItem("List item 3", "Some explanatory text", 'c', nil). AddItem("List item 4", "Some explanatory text", 'd', nil). AddItem("Quit", "Press to exit", 'q', nil) } ``` <img width="643" alt="image" src="https://github.com/rivo/tview/assets/66276367/b5236208-5d69-4a44-8968-b150440fb6f0">
kerem closed this issue 2026-03-04 01:07:08 +03:00
Author
Owner

@justlunix commented on GitHub (Mar 11, 2024):

Well, I knew it was something simple. Of course I need to call the methods without actually replacing the variable by the returned struct. :)

list := tview.NewList().
	AddItem("List item 1", "Some explanatory text", 'a', nil).
	AddItem("List item 2", "Some explanatory text", 'b', nil).
	AddItem("List item 3", "Some explanatory text", 'c', nil).
	AddItem("List item 4", "Some explanatory text", 'd', nil).
	AddItem("Quit", "Press to exit", 'q', nil)

list.SetBorder(true).
	SetTitle("Connections")

return list
<!-- gh-comment-id:1987795235 --> @justlunix commented on GitHub (Mar 11, 2024): Well, I knew it was something simple. Of course I need to call the methods without actually replacing the variable by the returned struct. :) ```go list := tview.NewList(). AddItem("List item 1", "Some explanatory text", 'a', nil). AddItem("List item 2", "Some explanatory text", 'b', nil). AddItem("List item 3", "Some explanatory text", 'c', nil). AddItem("List item 4", "Some explanatory text", 'd', nil). AddItem("Quit", "Press to exit", 'q', nil) list.SetBorder(true). SetTitle("Connections") return list ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#701
No description provided.