Ananiya
09/17/2022, 2:54 PMJavaFXPanel
composable [https://github.com/JetBrains/compose-jb/issues/519#issuecomment-804030550] and was trying to display a stream of data from Channels
inside it however when Recomposing JavaFXPanel it suddenly stop to listen for the channel and clears the view so to figure out what's going on created a simple composable containing either of those
// v1
JavaFXPanel(jfxpanel: JFXPanel, container: Container){
Platform.runLater {
print("hello")
}
}
// v2
JavaFXPanel(jfxpanel: JFXPanel, container: Container){
CoroutineScope(JavaFx).launch {
print("hello")
}
}
overall started with v1 prints hello and never made it when it recompose, v2 was identical too
also tried to create custom panel by adding SideEffect
which barely do to a thing
fun JavaFXPanel(
root: Container,
panel: JFXPanel,
onCreate: () -> Unit
) {
val container = remember { JPanel() }
val density = LocalDensity.current.density
Layout(
content =
{}
,
modifier = Modifier.onGloballyPositioned { childCoordinates ->
val coordinates = childCoordinates.parentCoordinates!!
val location = coordinates.localToWindow(Offset.Zero).round()
val size = coordinates.size
container.setBounds(
(location.x / density).toInt(),
(location.y / density).toInt(),
(size.width / density).toInt(),
(size.height / density).toInt()
)
container.validate()
container.repaint()
},
measurePolicy = { _, _ ->
layout(0, 0) {}
}
)
DisposableEffect(Unit) {
onCreate()
container.layout = BorderLayout(0, 0)
container.add(panel)
root.add(container)
onDispose {
root.remove(container)
}
}
SideEffect {
onCreate()
}
}