https://kotlinlang.org logo
Title
h

Humphrey

11/25/2021, 12:27 PM
Hello guys, in my early days programming in SWT I created a UI with Tabs, here is an example https://www.roseindia.net/tutorials/swt/create-tabs.shtml Is there a way to do the same in compose for desktop? Any link to documentation or example would be nice. Or other reason why not to go that way.
d

Didier Villevalois

11/25/2021, 1:29 PM
Something like this?
@Composable
fun MyAppTabs() {
    var tabIndex by remember { mutableStateOf(0) }
    val tabTitles = listOf("Hello", "There", "World")

    Column {
        TabRow(selectedTabIndex = tabIndex) {
            tabTitles.forEachIndexed { index, title ->
                Tab(
                    selected = tabIndex == index,
                    onClick = { tabIndex = index },
                    text = { Text(text = title) }
                )
            }
        }
        when (tabIndex) {
            0 -> Text("Hello content")
            1 -> Text("There content")
            2 -> Text("World content")
        }
    }
}
Source: https://www.rockandnull.com/jetpack-compose-swipe-pager/
h

Humphrey

11/25/2021, 1:34 PM
Thanks I think this will do the work!
🎉 2
k

Kebbin

11/27/2021, 1:57 AM
Interesting! Thankyou!