Is it possible to use variable resolution in "fx: define" in javafx

I am trying to define dynamic evaluated variables using fx: define, but I cannot get a variable that can be evaluated from another, I don’t know if this is possible?

<GridPane hgap="${10*m.dp}" vgap="${10*m.dp}" xmlns="http://javafx.com/javafx/8.0.51" xmlns:fx="http://javafx.com/fxml/1"> <fx:define> <Measurement fx:id="m" /> <!-- This works, but is not what I need --> <Double fx:id="width" fx:value="300" /> <!-- This doesn't work --> <!-- <Double fx:id="width" fx:value="${300*m.dp}" /> --> </fx:define> <padding> <Insets bottom="$width" left="$width" right="$width" top="$width" /> </padding> <Text text="hello" /> <Button GridPane.rowIndex="1" text="button" prefWidth="${300*m.dp}" /> <Button GridPane.rowIndex="2" text="button2" prefWidth="$width" /> </GridPane> 

I want to calculate the width from my calculated dp here (density-independent pixel - value 1 on the HD screen, 2 on the 4K screen, 0.xx on the screen with a width of 1600 pixels). The variable "width" that I want should be used in a very large component in my real case, so I need a variable to execute it.

Java code to run

 public class Measurement { private double dp; public Measurement(){ Screen primary = Screen.getPrimary(); dp=primary.getBounds().getWidth()/1920; } /** * Equivalent of 1 px in 1920. */ public double getDp(){ return dp; } public void setDp (double dp) { this.dp = dp; } } public class MApplication extends Application { public static void main (String[] args) { launch (args); } @Override public void start (Stage primaryStage) throws Exception { FXMLLoader fxmlLoader = new FXMLLoader(); Parent root = fxmlLoader.load(getClass().getResource("index.fxml").openStream()); Scene scene = new Scene(root, 300, 275); primaryStage.setMaximized(true); primaryStage.setScene(scene); primaryStage.show (); } } 

Actually, I don’t understand which expression can be used and where, I see a lot of answers here: Can I use an arithmetic expression in FXML?

here: Link font size in JavaFX?

and here: http://docs.oracle.com/javase/8/javafx/api/javafx/fxml/doc-files/introduction_to_fxml.html#expression_binding

I do not understand in which case I can use the language of expression, is there a specification?

Edited: I adedd Link to javafx-8 documentation, and I deleted my legacy javaFX-2 comment

+5
source share

All Articles