Sorry, I did not find a better name to describe my problem:
I want to update the JavaFX label with the value of TextField .
In some constellation, an already updated value will not be displayed until I resize the window or go beyond the GridPane containing my label and my TextField .
As soon as I do this, the value will be updated immediately.
It seems that every element in the following FXML matters:
<?xml version="1.0" encoding="UTF-8"?> <?language javascript?> <?import javafx.scene.control.*?> <?import javafx.scene.layout.*?> <VBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"> <fx:script> function updateLabel() { label.setText(textfield.getText()); } </fx:script> <GridPane> <TextField fx:id="textfield" onKeyReleased="updateLabel()" /> <Label fx:id="label" text="Just type..." GridPane.columnIndex="1" /> <DatePicker GridPane.columnIndex="2" /> </GridPane> <ScrollPane><TableView><columns><TableColumn/></columns></TableView></ScrollPane> </VBox>
- If I remove the
DatePicker or place it outside of the GridPane , the Label will be updated immediately. - If I delete
ScrollPane or TableView , Label will immediately update
You can try this by simply downloading the FXML file like this (but you need JDK8 due to DatePicker ):
package sample; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage; public class Main extends Application { @Override public void start(Stage primaryStage) throws Exception { Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("main.fxml")); primaryStage.setScene(new Scene(root)); primaryStage.show(); } public static void main(String[] args) { launch(args); } }
Is this a bug (known?)? Or am I missing something regarding caching strategies or something similar in JavaFX?
/opt/java8/bin % ./java -version java version "1.8.0_11" Java(TM) SE Runtime Environment (build 1.8.0_11-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode) /opt/java8/bin % uname -a Linux venus 3.15.7-1-ARCH
source share