I was looking for a method for this, but I found this question unanswered .
I am developing on a 1366x768 laptop, I use JavaFX to create a graphical interface (sorry, but I can’t post the code, it is basically AnchorPane containing a couple of GridPanes that contain more GridPanes that contain shortcuts, TextFields and a couple of diagrams).
The problem occurs when I load a project at a different resolution (1920x1080 or 1600x900).
I am using stage.setMaximized(true); , but it only scales the background, the stage itself, so all elements and containers (panels, labels, text fields .....) remain the same size as with a resolution of 1366x768, which makes the GUI “not suitable” at resolutions that are not exactly 1366x768.
I hope I have explained my problem well enough, my English is far from perfect.
Does anyone have any suggestions on how to scale elements with scene resolution?
(I need the software to be maximized or full-screen on each monitor, so a fixed resolution (1366x768, for example) does not seem like a good solution).
Thanks to everyone.
Update:
I just created a small example. This is a 2x1 GridPane inside the standard JavaFX AnchorPane, I added two example buttons to the grid panel.
<AnchorPane minHeight="-Infinity" minWidth="-Infinity" prefHeight="300.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" > <children> <GridPane prefHeight="300.0" prefWidth="400.0"> <columnConstraints> <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> </columnConstraints> <rowConstraints> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> </rowConstraints> <children> <Button fx:id="example1" mnemonicParsing="false" text="Example 2" GridPane.halignment="CENTER" GridPane.valignment="CENTER" /> <Button fx:id="example2" mnemonicParsing="false" text="Example 2" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="CENTER" /> </children> </GridPane> </children>
This code looks good on a 400x300 screen (too small, I know, this is just an example), when I scale it to 1366x768 (not a real full screen, just stage.setMaximized(true); ), GridPane does not scale, only the stage itself, so I have a full screen background with a 400x300 panel (with its small buttons) in the upper left corner of the screen.
TL DR: example code: the buttons remain in the upper left corner of the screen, and the rest is just empty space when I increase the resolution.
Update 2; Forgot java code.
Parent root = FXMLLoader.load(getClass().getResource("UI.fxml")); Scene scene = new Scene(root, java.awt.Toolkit.getDefaultToolkit().getScreenSize().width, java.awt.Toolkit.getDefaultToolkit().getScreenSize().height); stage = new Stage(); stage.setMaximized(false); stage.setScene(scene); stage.setTitle("Example Menu"); stage.show();