jvmTest.io.mths.swing.flow.util.WithAttached.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swing-flow Show documentation
Show all versions of swing-flow Show documentation
Kotlin Flow integration for Swing.
The newest version!
package io.mths.swing.flow.util
import javax.swing.JComponent
import javax.swing.JPanel
/**
* Executes [actions] with a receiver attached to a [JPanel],
* to ensure the flow bindings are active.
*/
internal inline fun withAttached(
component: Type,
actions: Type.() -> Unit
) {
val parent = JPanel().apply {
add(component)
}
component.actions()
parent.removeAll()
}