Search code examples
javafxgriffon

Griffon FXML button text value is overwritten


Griffon 2.10.0

FXML:

<Button layoutX="172.0" layoutY="45.0" JavaFXUtils.griffonActionId="click2"
        mnemonicParsing="false" text="Test"
        prefWidth="200.0"
        />

TestView.groovy:

void initUI() {
builder.application(title: application.configuration['application.title'], name: "settingsWindow",
        centerOnScreen: true, resizable: false) {
    scene {
        def node = loadFromFXML("views/test.fxml")

        connectActions(node, controller)

        inputx.textProperty().bindBidirectional(model.inputProperty())

        fxml node

       }
    }
}

Shows this button with the text "Click2"
enter image description here

Why is the text="Test"configuration in the FXML overwritten by the griffonActionId name?

It works when I use this in FXML:

<Button fx:id="btn1" ...

And in TestView.groovy:

@FXML private Button btn1  
...
btn1.text = 'Test'

This displays:
enter image description here

Is this the proper the way to set the button text?


Solution

  • This is expected behavior. Buttons configured via Griffon actions will bind their properties to action properties. The button's text is bound to the action's name by default. You can overrode this behavior by setting the button's text explicitly in code, like you did.