简体   繁体   English

当字符串变量更改 TornadoFX 时更改 TextArea 文本

[英]Change TextArea Text When String Variable Changes TornadoFX

I have a controller with a string variable, and I would like the text value of a TextArea to change when the controller's string variable changes.我有一个带有字符串变量的控制器,我希望 TextArea 的文本值在控制器的字符串变量更改时更改。

class MyView: View() {
...
   button("Run Test").action {
      runAsync {
          for(test in testList){
              controller.updateText = "running" + test.name
              run(test)
          }
      }    
   }
...
   scriptRanArea = textarea {
      text = controller.updateText
   }
...
}

This is the fastest way I know how to accomplish this, but I don't really know which design pattern you want to use:这是我知道如何完成此操作的最快方法,但我真的不知道您要使用哪种设计模式:

class MyView: View() {
   val controller: MyController by inject()

   override val root = vbox {
      textarea(controller.myTextProperty)
   }
}

class MyController: Controller() {
   val myTextProperty = SimpleStringProperty()
}

The inject method automatically finds the controller within the TornadoFX Scope, or creates one if not found, when it is first referenced.当第一次引用时,inject 方法会自动在 TornadoFX 范围内找到控制器,或者如果没有找到则创建一个。 The TornadoFX text area builder function binds the string property from the controller to the TextArea when it is passed in as a param. TornadoFX 文本区域构建器函数将字符串属性从控制器绑定到 TextArea,当它作为参数传入时。 Keep in mind though, writing in the text area will now automatically change the value in the controller's property and vice versa.但是请记住,在文本区域中书写现在将自动更改控制器属性中的值,反之亦然。 If you don't want that functionality, you will have to update your question to be more specific to your needs.如果您不想要该功能,则必须更新您的问题以更具体地满足您的需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM