frank
08/28/2020, 2:20 PMval
my Javafx controls but I don't get desired result in Type-Safe Builders of Tornadofx.
¿How can return type-safe builder instead javaFx control?
My Code: I can't define my label as type-safe builder instead Label
class Portal : View("") {
val lblImgWarn by lazy { label("File not found") {} }
gridpane {
row {
add(lblImgWarn)
lblImgWarn.graphic = imageview(image) {
fitHeight = 32.0
isPreserveRatio = true
}
}
}
}
Expected Code:
class Portal : View("") {
val lblImgWarn by lazy { label("File not found") {} } // I don't know how to return a type-safe builder instead Label
gridpane {
row {
lblImgWarn{
graphic = imageview(image) {
fitHeight = 32.0
isPreserveRatio = true
}
}
}
}
}
Marshall
08/28/2020, 2:57 PMMarshall
08/28/2020, 2:59 PMclass Portal : View("") {
var lblImgWarn: Label by singleAssign()
gridpane {
row {
lblImgWarn = label{
graphic = imageview(image) {
fitHeight = 32.0
isPreserveRatio = true
}
}
}
}
}
Marshall
08/28/2020, 3:00 PMMarshall
08/28/2020, 3:01 PMMarshall
08/28/2020, 3:05 PMMarshall
08/28/2020, 3:06 PMclass Portal : View("") {
val text = simpleStringProperty("Label")
gridpane {
row {
label(text){
graphic = imageview(image) {
fitHeight = 32.0
isPreserveRatio = true
}
}
}
}
}
Marshall
08/28/2020, 3:06 PMfrank
08/28/2020, 7:28 PMLabel + input + Btn
for reused controls and also I created extends function in Pane class for to automatically add controls to my Pane without calling the add()
function.
Could this approach give me problems in the future? Suggestions for an alternative?
Sample Code:
data class InputChooseFolder(val label: Label, val input: TextField, val btnFolder: Button){}
class Portal : View("") {
fun Pane.inputChooseFolder(txt: String, inputID: String = "", tooltipMsg: String): InputChooseFolder{
val label = label(txt)
val input = textfield {
id = inputID
promptText = txt
prefWidth = 300.0
tooltip = tooltip(tooltipMsg) { }
}
val btn = btnFolderChooser(input)
return InputChooseFolder(label, input, btn)
}
vbox {
row {
inputRoot = inputChooseFolder("Root Path:", "inputRoot","Insert root Path of files")
}
row {
inputDest = inputChooseFolder("Dest Path:", "inputDest", "Path on store JSON generated")
}
}
}
melatonina
08/28/2020, 7:31 PMMarshall
08/28/2020, 7:33 PMMarshall
08/28/2020, 7:34 PMMarshall
08/28/2020, 7:34 PMMarshall
08/28/2020, 7:35 PM/**
* Show a file open dialog for selecting a profile configuration to load.
*
* @param fileName The file name with the path for the initial directory
* @param otherFileName The file name for initial directory if fileName is blank
*/
private fun browseFile(fileName: String, otherFileName: String = ""): File? {
val extJson = FileChooser.ExtensionFilter("JSON files (*.json)", "*.json")
val extAll = FileChooser.ExtensionFilter("All files (*.*)", "*.*")
val initialFileName = if (fileName.isNotBlank()) fileName else otherFileName
val f = File(initialFileName)
val initDir: File? = if (f.exists()) f.parentFile else null
val files = chooseFile(title = "Open Profile Configuration",
initialDirectory = initDir,
filters = arrayOf(extJson, extAll),
mode = FileChooserMode.Single
)
return files.firstOrNull()
}
Marshall
08/28/2020, 7:36 PMfrank
08/28/2020, 7:40 PMMarshall
08/28/2020, 7:41 PMfrank
08/28/2020, 7:42 PMMarshall
08/28/2020, 7:46 PMimport tornadofx.*
class ChooseFolderFragment : Fragment() {
val lblTxt = stringProperty("")
val txtPath = stringProperty("")
override val root = flowpane {
label(lblTxt)
textfield(txtPath) {
}
button {
chooseFile()
}
}
}
Marshall
08/28/2020, 7:46 PMvbox {
add(ChooseFolderFragment())
}
Marshall
08/28/2020, 7:47 PMMarshall
08/28/2020, 7:48 PMMarshall
08/28/2020, 7:48 PMvbox {
val chooser = ChooseFolderFragment()
add(chooser)
chooser.lblText.set("Test")
}
frank
08/28/2020, 7:53 PM