diff --git a/src/main/java/tornadofx/FX.kt b/src/main/java/tornadofx/FX.kt index a2f54cc..58ca0ed 100644 --- a/src/main/java/tornadofx/FX.kt +++ b/src/main/java/tornadofx/FX.kt @@ -694,14 +694,11 @@ fun EventTarget.getChildList(): MutableList? = when (this) { } @Suppress("UNCHECKED_CAST", "PLATFORM_CLASS_MAPPED_TO_KOTLIN") -private fun Parent.getChildrenReflectively(): MutableList? { - val getter = this.javaClass.findMethodByName("getChildren") - if (getter != null && java.util.List::class.java.isAssignableFrom(getter.returnType)) { - getter.isAccessible = true - return getter.invoke(this) as MutableList - } - return null -} +private fun Parent.getChildrenReflectively(): MutableList? = this.javaClass + .findMethodByName("getChildren") + ?.takeIf { java.util.List::class.java.isAssignableFrom(it.returnType) } + ?.takeIf { getter -> getter.canAccess(this) || getter.trySetAccessible() } + ?.let { getter -> getter.invoke(this) as MutableList } var Window.aboutToBeShown: Boolean get() = properties["tornadofx.aboutToBeShown"] == true diff --git a/src/test/kotlin/tornadofx/testapps/TableViewCheckboxReflection.kt b/src/test/kotlin/tornadofx/testapps/TableViewCheckboxReflection.kt new file mode 100644 index 0000000..59196b2 --- /dev/null +++ b/src/test/kotlin/tornadofx/testapps/TableViewCheckboxReflection.kt @@ -0,0 +1,19 @@ +package tornadofx.testapps + +import javafx.beans.property.SimpleBooleanProperty +import tornadofx.* + +class TableViewCheckboxApp : App(TableViewCheckbox::class) + +class Model { + val booleanProperty = SimpleBooleanProperty() +} + +class TableViewCheckbox : View() { + val items = observableListOf(Model()) + + override val root = tableview(items) { + column("Checkbox", Model::booleanProperty) + .useCheckbox() + } +}