Strange behavior when updating a label using TextField (Possible error in JavaFX8)?

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> <!-- a ScrollPane containing a TableView containing a TableColumn --> <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 #1 SMP PREEMPT Mon Jul 28 20:06:17 CEST 2014 x86_64 GNU/Linux 
+5
source share
1 answer

Since the shortcut is usually static, you probably need to call a redraw at your stage. Can you add this to the update label method specified in the fxml file?

-1
source

Source: https://habr.com/ru/post/1200498/


All Articles