hello-world
の例がhttps://github.com:JetBrains/kotlin-examples.gitで始まり、TornadoFXを使用するように修正されました。tornadofxアプリケーション内のobservableArrayListにバインドされた項目のフィルタリングを許可するビューをどのようにリファクタリングするのですか?
これは、アイテムのリストを表示するアプリです。あなたはリストに追加することができ、RequestView
は自動的にすべてのアイテムを表示します。
保存されているアイテムがobservableArrayList
にバインドされていますが、下部にTextView
を使用してフィルタを実装したいと考えています。しかし、私はRequestView
で内部的に管理されている新しいリストを作成し、そこからフィルタリングする方法、またはそれを行う方法を理解するのが苦労しています。
package demo
import javafx.collections.FXCollections
import javafx.geometry.Pos
import javafx.scene.control.TextField
import javafx.scene.layout.VBox
import javafx.scene.text.FontWeight
import tornadofx.*
class helloWorldApp : App(HelloWorld::class) {
}
class HelloWorld : View() {
override val root = VBox()
var requestView: RequestView by singleAssign()
var filterField: TextField by singleAssign()
init {
with(root) {
requestView = RequestView()
this += requestView
filterField = TextField()
this += filterField
}
requestView.items.add("Hi there")
requestView.items.add("Another one")
}
}
class RequestView() : View() {
var items = FXCollections.observableArrayList<String>()
override val root = listview(items) {
cellFormat {
graphic = cache {
form {
fieldset {
label(it) {
alignment = Pos.CENTER_LEFT
style {
fontSize = 15.px
fontWeight = FontWeight.BOLD
}
}
}
}
}
}
}
}
これは参考になる場合があるので、ここにbuild.gradleファイルがあります。
buildscript {
ext.kotlin_version = '1.1.2'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin'
apply plugin: 'application'
mainClassName = 'demo.helloWorldApp'
defaultTasks 'run'
repositories {
mavenCentral()
}
tasks.compileKotlin.kotlinOptions.jvmTarget = "1.8"
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
testCompile 'junit:junit:4.11'
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
compile 'no.tornado:tornadofx:1.7.10'
}
task wrapper(type: Wrapper) {
gradleVersion = "2.7"
}