Kotlin+JavaFX系列
- 使用Kotlin开发JavaFX
- Windows下的JavaFX桌面应用程序打包ABC
- Kotlin编写JavaFX的顺滑
- JavaFX动画:有趣的AnimationTimer
- JavaFX应用程序图标
- JavaFX专业开发者与业余开发者之间就差一个一个Icon packs
- JavaFX七巧板游戏:布局窗格Panes
- JavaFX七巧板游戏:布局控件
- JavaFX+Kotlin游戏从入门到放弃:拯救蛇蛇大作战又名454行实现几何数独游戏
- Kotlin编写JavaFX的顺滑之数据控件(一)列表视图ListView
- Kotlin编写JavaFX的顺滑之数据控件(二)表视图TableView基础应用
- Kotlin编写JavaFX的顺滑之数据控件(二)表视图TableView基础深入浅出
效果先行
一个列表视图控件,可以实现展示一系列项,每一个项对应ListView界面中的一行。这个控件很简单,但是也很好用。当采用Kotlin编写的时候,就更好用了。
- 增加项
- 清除项
- 选择项
- 原位编辑

再给代码
data class Kid(
var firstname: String = "",
var middleName: String = "",
var lastname: String = "",
var age: Int = 0
)
class DefaultFocusInScope {
private val _ff = SimpleBooleanProperty(false)
/**
* Set n be the focused node in the scope, when focused, call func
* @param n Node
* @param func Function0<Unit>
*/
fun focusNode(n: Node, func: () -> Unit) {
_ff.addListener {
_, _, _ ->
Platform.runLater {
n.requestFocus()
func()
}
}
}
/**
* set focus to the default focused node in this scope.
*/
fun focus() {
_ff.value = !(_ff.value)
}
}
fun randString(len: Int = 10, from: Int = 97, until: Int = 122) = (1..len).map {
Random.nextInt(from, until).toChar()
}.toTypedArray().joinToString(separator = "") {
"$it" }
fun listViewDemo(): Parent {
val names = SimpleObjectProperty(FXCollections.observableArrayList<Kid>())
return BorderPane().apply {
padding = Insets(5.0)
center = ListView<Kid>().apply {
isEditable = true
itemsProperty().bindBidirectional(names)
setCellFactory {
object : ListCell<Kid>() {
val thisKid = SimpleObjectProperty(Kid())
override fun updateItem(item: Kid?, empty: Boolean) {
super.updateItem(item, empty)
if (!empty && item != null) {
graphic = HBox().apply {
thisKid.value = item
children.add(Label(item.firstname).apply {
HBox.setHgrow(this, Priority.ALWAYS)
maxWidth = Double

最低0.47元/天 解锁文章
5912

被折叠的 条评论
为什么被折叠?



