I am trying to run the following example from an FXML link :
This example consists of declaring a String variable in a JavaScript script and then using it in FXML with the $ operator to display a string in a shortcut.
The problem is that when I run this example with Java 8u40, the shortcut is empty and not showing the declared string.
JavaFxComponent.java:
public class JavaFxComponent extends VBox { public JavaFxComponent() throws Exception { FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/JavaFxComponent.fxml")); fxmlLoader.setRoot(this); fxmlLoader.load(); } }
JavaFxComponent.fxml:
<?xml version="1.0" encoding="UTF-8"?> <?language javascript?> <?import javafx.scene.*?> <?import javafx.scene.control.*?> <?import javafx.scene.layout.*?> <fx:root type="javafx.scene.layout.VBox" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml"> <fx:script> var myText = "This is the text of my label."; </fx:script> <Label text="$myText" /> </fx:root>
JavaFxTest:
public class JavaFxTest extends Application { @Override public void start(Stage primaryStage) throws Exception { primaryStage.setScene(new Scene(new JavaFxComponent())); primaryStage.show(); } public static final void main(String[] args) { launch(args); } }
javafx javafx-8
Romain moreau
source share