JavaFX Scene Builder - Using Variable Values

I'm trying to use Scene Builder to handle the complex GUI I'm working on, and for simplicity I'm trying to set the height and width of the window to half the height of the user's screen.

The problem I am facing is that Scene Builder will not allow me to enter custom values ​​in the Pref Width and Pref Height fields, and I will allow me to enter something in the USE_COMPUTED_SIZE line

Looking directly at the FXML file, I found the following:

<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefWidth="0.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="sudokusolver.FXMLDocumentController"> 

But I could not find possible replacement values ​​for "-Infinity" anywhere. I am trying to do something like:

 Screen.getPrimary().getVisualBounds().getHeight() / 2; 

Any tips or ideas on setting such values?

+5
source share
1 answer

hmmmm, okey ...

I'm not sure what you are looking for, if you need to set the height and width of your windows to half the height and width of the user's screen, there are many ways, the simplest of them is as follows:

 public class Main extends Application { public void start(Stage primaryStage) throws Exception { Parent page = (Parent) FXMLLoader.load(Main.class.getResource("Untitled.fxml")); // get the user screen size Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); // get width and height of screen and divide them by two double width = screenSize.getWidth()/2; double height = screenSize.getHeight()/2; // set the result to the scene Scene scene = new Scene(page,width,height); primaryStage.setScene(scene); primaryStage.setTitle("Window with half size of screen"); primaryStage.show(); } public static void main(String[] args) { launch(); } } 

In addition, you said β€œEliminate window height and width ..." if you want to prevent the user from resizing the window so that you can use the code below:

  primaryStage.setResizable(false); 
0
source

All Articles