I’m creating a board game in JavaFx, and it works fine in my desktop PC, with a 1920×1080 screen. When i try to open it in my Laptop (which is 1920×1080 as well, but with the default screen size at 125%, it stops working). The only way to make the app work is to run it on a 1920×1080 screen with default scree size at 100%
I need a way to scale the whole stage to the right resolution
This is my Main.java:
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws IOException {
final double WIDTH = Toolkit.getDefaultToolkit().getScreenSize().getWidth();
final double HEIGHT = Toolkit.getDefaultToolkit().getScreenSize().getHeight();
Parent board = FXMLLoader.load(getClass().getResource("/board.fxml"));
Pane innerBoard = ((Pane)board.getChildrenUnmodifiable().get(0));
Assert.assertCmp(innerBoard.getId(), "BOARD");
Scene scene = new Scene(board, WIDTH, HEIGHT);
scene.getStylesheets().add(getClass().getResource("/style.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.setFullScreen(true);
primaryStage.setResizable(true);
innerBoard.setVisible(false);
primaryStage.setFullScreenExitHint("");
primaryStage.show();
innerBoard.setVisible(true);
}
}
This is the FXML:
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="1080.0" prefWidth="1920.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Pane id="BOARD" fx:id="innerBoard" layoutX="356.0" layoutY="-7.0" style="-fx-background-color: #cfffd1;">
<children>
<!-- Lots of children -->
</children>
</Pane>
</children>
</Pane>