compose-multiplatform
compose-multiplatform copied to clipboard
MenuBar not visible in 1.0.0-beta5
When I switch tabs dynamically and switch to a Swing control in a SwingPanel, MenuBar doesn't show up, it needs to manually resize the window to show up.
How to solve this problem? What are the alternative methods?
Could you share some small reproducer to this issue?
Also you could try version 1.0.0, that has been released recently - it contains quite a few bugfixes, so this issue could've also been fixed.
I tried version 1.0.0 and still have problems.
You can reproduce the problem with the official Demo -widgets- Gallery.
You need to make 4 changes to the Demo.
- Modify main.kt
MenuBar { Menu("File", mnemonic = 'F') { Item("New", onClick = { }) Item("Open", onClick = { }) Item("Import", onClick = { }) } }
- Modify Chips.kt
ComboBox("", 0, mutableListOf("1", "2"), onItemSelected = { print("lihj, ComboBox $it") })
3.Add file ComboBox.kt in Common lib
@Composable expect fun ComboBox( title: String?, selectIndex: Int? = 0, items: MutableList<String>, onItemSelected: (String) -> Unit )
4.Add class ComboBox.kt in desktop platform
`@Composable actual fun ComboBox( title: String?, selectIndex: Int?, items: MutableList<String>, onItemSelected: (String) -> Unit ) { Row(modifier = Modifier .fillMaxWidth() .wrapContentHeight() .padding(0.dp, 8.dp, 0.dp, 0.dp), verticalAlignment = Alignment.Top, horizontalArrangement = Arrangement.Center) { title?.let { Text(text = title, fontSize = 14.sp, modifier = Modifier.padding(0.dp, 6.dp, 0.dp, 0.dp)) } SwingPanel( background = Color.White, modifier = Modifier .size(100.dp, 30.dp), factory = { JPanel().apply { background = JColor.WHITE // add(JComboBox(items.toTypedArray()).apply { // selectedIndex = selectIndex ?: 0 // addItemListener { // if (it.stateChange == ItemEvent.SELECTED) { // onItemSelected.invoke(it.item as String) // } // } // }) val value = SpinnerNumberModel(5,0,10,1) layout = BoxLayout(this, BoxLayout.Y_AXIS) .apply {
val spinner = JSpinner(value).apply {
setBounds(0,0,50,30)
}
add(spinner)
}
}
}
)
}
}`
I tried with 1.0.0 on Mac (only added MenuBar itself as other changes doesn't seem related to it). What is your OS?
I tried with 1.0.0 on Mac (only added MenuBar itself as other changes doesn't seem related to it). What is your OS?
I use Windows 10 Professional.
I guess this has something to do with Swing showing the hide on the Compose UI.
I also got the same problem frequently. The menu is not visible until windows got resized. Calling window.invalidate()
does not hepl too.
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.