import javafx.collections.FXCollections
import javafx.collections.ObservableList
import javafx.scene.control.TreeItem
import javafx.scene.layout.Priority
import tornadofx.*
import java.io.File
import java.text.SimpleDateFormat
import java.util.*
class APP22a : App(MainView22::class)
class MainView22a : View("tornadofx入门22_treeview") {
val fileSelected = objectProperty<File>()
val path = stringProperty()
override val root = borderpane {
center = hbox(5) {
}
top = hbox(5) {
label(path)
}
left = vbox(10) {
treeview<File> {
root = TreeItem(File("my computer"))
File.listRoots().map { file ->
root.children.add(FileTreeItem(file))
}
// 两种方式实现项目点击事件
// bindSelected(fileSelected)
// fileSelected.onChange { file->
// path.value=file?.path
// }
selectionModel.selectedItemProperty().onChange { item ->
path.value = item?.value?.path
}
vgrow = Priority.ALWAYS
}
}
bottom {
}
setPrefSize(1000.0, 600.0)
paddingAll = 10.0
style {
fontSize = 16.px
}
}
}
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。