7

Is it possible to make FXML property bindings (disable="${myNode.disable}" to bind the disable property with myNode's disabled value) from within scene builder itself?

The only way I could get it done was by manually editing the output file. Here's an example:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.VBox?>

<VBox spacing="10.0" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <TextField disable="${checkbox.selected}"/>
      <CheckBox fx:id="checkbox" mnemonicParsing="false" text="Disable Field" />
   </children>
   <opaqueInsets>
      <Insets />
   </opaqueInsets>
   <padding>
      <Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
   </padding>
</VBox>

And loaded:

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class App extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        VBox parent = FXMLLoader.load(getClass().getResource("FxmlBindingTest.fxml"));

        Scene scene = new Scene(parent);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);

    }

}

When I load back this file to scene builder, there's a yellow caution icon over that node:

Scene builder snip

What's really interesting, if I load a preview from scene builder, the values are not bound.

Scene builder will not overwrite or remove the binding text on any change, other than a change on that property itself - as expected.

Mordechai
  • 15,437
  • 2
  • 41
  • 82
  • 7
    See this [issue](https://bitbucket.org/gluon-oss/scenebuilder/issues/97/not-able-to-drag-controls-in-scenebuilder) at the Scene Builder OSS repository. If you read the issue until the end, you will find the reason why bindings on Scene Builder were disabled in the FXMLLoader code. Nothing that can't be reviewed... – José Pereda Nov 30 '17 at 08:56
  • 3
    @JoséPereda you should probably make this an answer, just include the relevant text from the link you provided. – MMAdams Nov 30 '17 at 21:14
  • New link to the issue: https://github.com/gluonhq/scenebuilder/issues/97 – Puce Feb 24 '20 at 11:38

0 Answers0