佈局文件:java
demo.fxml
<?import javafx.geometry.Insets?> <?import javafx.scene.control.Button?> <?import javafx.scene.control.Label?> <?import javafx.scene.layout.BorderPane?> <?import javafx.scene.layout.VBox?> <?import javafx.scene.text.Font?> <BorderPane xmlns="http://javafx.com/javafx/null" xmlns:fx="http://javafx.com/fxml/1"> <padding> <Insets top="20" right="20" bottom="20" left="20"/> </padding> <center> <VBox alignment="CENTER" spacing="10"> <Label text="0" fx:id="counterLabel"> <font> <Font size="20"/> </font> </Label> <Button text="Click to increment" onAction="#increment"/> </VBox> </center> </BorderPane>
tornadofx view文件:ide
class MainView : View("fxml ui"){ override val root : BorderPane by fxml("/fxml/demo.fxml") val counter = intProperty() val counterLabel : Label by fxid() val myLabel = Label("hhhhhhhhhhhh") fun increment() { counter.value += 1 root.center.add(myLabel) } init { counterLabel.bind(counter) } }