Created
January 26, 2019 21:37
-
-
Save kururu-abdo/4da2f1512ba140e5df077b449ddf4110 to your computer and use it in GitHub Desktop.
how to auto fill combobox in tornadofx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.demo.view | |
import org.junit.Assert | |
import org.junit.Test | |
import org.testfx.api.FxToolkit | |
import org.junit.Assert.* | |
import javafx.beans.property.SimpleStringProperty | |
import javafx.scene.Node | |
import javafx.scene.control.* | |
import javafx.scene.layout.Background | |
import javafx.scene.layout.BackgroundFill | |
import javafx.scene.layout.BackgroundSize | |
import javafx.scene.paint.Color | |
import javafx.scene.text.Font | |
import tornadofx.* | |
import tornadofx.controlsfx.statusbar | |
import java.io.FileInputStream | |
import javax.json.JsonObject | |
import org.junit.Assert.* | |
class testAuto : View("My View",Button("op")) { | |
var js=""" | |
[ | |
{"name":"abdo" | |
"password":"796990" | |
] | |
""".trimIndent() | |
private var nmtxt: TextField by singleAssign() | |
var pstxt:PasswordField by singleAssign() | |
var model =personModel() | |
override val root = form { | |
fieldset { | |
this.style{ | |
backgroundColor+=Color.CADETBLUE | |
font= Font.loadFont(FileInputStream("F:\\Fonts\\LHANDW.TTF"),20.0) | |
} | |
field("username") { | |
textfield(model.name) { | |
nmtxt=this | |
}.required() | |
} | |
field("password") { | |
passwordfield(model.password) { | |
pstxt=this | |
}.required() | |
} | |
button("Log in") | |
{ | |
useMaxSize = true | |
style { | |
backgroundColor += Color.GREEN | |
} | |
action{ | |
model.commit() | |
} | |
} | |
} | |
} | |
private var context=ValidationContext() | |
var nmval=context.addValidator(nmtxt,nmtxt.textProperty()){ | |
if(it!!.length<5) error("short name , please check name") else null | |
} | |
var psval=context.addValidator(pstxt,pstxt.textProperty()){ | |
if(it!!.contains("2012") ) null else {error("invalid password ,plz check password")} | |
if (it!!.contains("2012")) success("great") else warning("oops") | |
} | |
} | |
class person{ | |
var name=SimpleStringProperty() | |
var nmProperty by name | |
var password =SimpleStringProperty() | |
var pass by password | |
} | |
class personModel: ItemViewModel<person>(){ | |
var name=bind(person::nmProperty) | |
var password=bind(person::pass) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ooops!
this is a code
package com.example.demo.view
import javafx.beans.property.SimpleStringProperty
import javafx.collections.ObservableList
import javafx.scene.control.ComboBox
import javafx.scene.control.SelectionMode
import javafx.scene.control.SelectionModel
import tornadofx.*
import java.io.FileInputStream
class testcss : View("test css") {
var ic=icons()
init {
selectionModel.selectedItemProperty().onChange {
str = selectionModel.selectedItem!!.toString()
}
print(locss(str!!))
println(str)
comb1.selectionModel.selectedItemProperty().onChange {
items=locss(str!!)
}
return xc?.observable()
}
}
package com.example.demo.view
import javafx.beans.property.SimpleStringProperty
import javafx.collections.ObservableList
import javafx.scene.control.ComboBox
import javafx.scene.control.SelectionMode
import javafx.scene.control.SelectionModel
import tornadofx.*
import java.io.FileInputStream
class testcss : View("test css") {
var ic=icons()
init {
selectionModel.selectedItemProperty().onChange {
str = selectionModel.selectedItem!!.toString()
}
print(locss(str!!))
println(str)
comb1.selectionModel.selectedItemProperty().onChange {
items=locss(str!!)
}
return xc?.observable()
}
}
data class stat(var name:String, var local:List)